WebCheckBox disable Action without disabling control

  1. 5 weeks ago

    Tom D

    Jan 18 Pre-Release Testers, Xojo Pro

    I have a WebCheckBox that I have subclassed to include a property DisableAction As Boolean. I want to be able to prevent a mouse click from firing the action to change the checkbox value unless the property DisableAction is set to true. I do not want the checkbox itself to be disabled because it will be made transparent and because I am using a contextual menu to select "Edit" to set the DisableAction property to false and change the text color style of the checkbox to indicate the value is now changeable from its original setting.

    What is the best way to prevent the value changing so long as DisableAction is True?

  2. Dave S

    Jan 18 San Diego, California USA

    Since we don't know how you subclassed the actions... this is a guess

    // MouseDown Event
    If Disabled then return true 
  3. Louis D

    Jan 18 Pre-Release Testers, Xojo Pro Montreal, QC, Canada

    If DisableAction then Return True

    I see that Dave just beat me to the finish. :)

  4. Tim P

    Jan 18 Pre-Release Testers, Xojo Pro
    Edited 5 weeks ago

    Without providing some way for your user to know you're going to be ignoring their attempts to change the value of the checkbox, you'll drive them mad with clicking.

    If you're going to tell the user they can't change a checkbox, disable it. The visual cue lets them know you're not allowing changes, and the browser will handle not allowing them to change it.

    That being said, the code below will do what you ask without waiting for the round trip. Plus, if you handle the return in Xojo, you'd have to set the checkbox back to it's previous state (more confusion for the user).

    ExecuteJavaScript("document.getElementById('" + me.ControlID + "').setAttribute('onclick', 'return false');")

    I tested this, and it works on the checkbox. Xojo does something that allows the user to click on the label associated with the checkbox so that it behaves similar to desktop checkboxes. I've provided the example for how to disable the functionality; I'll leave you to explore, expand, and figure out how to disable clicking the label.

    Update: You will also have to check if you're ignoring the change with DisableAction in the ValueChanged event as it looks like that gets triggered even when the checkbox is not to do anything onclick.

  5. Tom D

    Jan 18 Pre-Release Testers, Xojo Pro

    Thanks Tim. I'll give that a try. As far as visual queues to the user, ALL text fields, Listboxes and checkboxes in this app must be enabled for editing via a contextual menu selection. This is an internal app that uses a web service to populate all the controls and if a user wants to change a value they have to be very intentional about it. I agree that normally I would disable the control but that means only checkboxes would have that appearance since all text fields are set to read only and Listboxes require a popup dialog to edit a specific field.

    Dave and Louis, Yeah I would use return True on a desktop app but that return type is not defined for a mouse down even on WebCheckBox which is why I posed this question.

  6. Tom D

    Jan 18 Pre-Release Testers, Xojo Pro

    Hi Tim,

    That JavaScript Code works great on the checkbox itself but if you actually click twice on the Checkbox text the Value will change. Any thoughts on how to disable that too?

  7. Louis D

    Jan 18 Pre-Release Testers, Xojo Pro Montreal, QC, Canada

    I would have sworn that I used it in a web app...

    Well, so much for memory. I will check as soon as I get back to my dev machine. Must have worked around this somehow. I use the weblistbox quite a bit in my current project.

  8. Tim P

    Jan 18 Pre-Release Testers, Xojo Pro
    Edited 5 weeks ago

    @Tom D Hi Tim,

    That JavaScript Code works great on the checkbox itself but if you actually click twice on the Checkbox text the Value will change. Any thoughts on how to disable that too?

    @Tim P Xojo does something that allows the user to click on the label associated with the checkbox so that it behaves similar to desktop checkboxes. I've provided the example for how to disable the functionality; I'll leave you to explore, expand, and figure out how to disable clicking the label.

    aka: I haven't had time to look into it :P

    Now that I'm looking at the source, it seems we'll have to get clever.
    brb, coming up with a solution because you had to go and peak my interest.

  9. Tom D

    Jan 18 Pre-Release Testers, Xojo Pro

    @Tim P brb, coming up with a solution because you had to go and peak my interest.

    I love it when a plan comes together.

    -image-

  10. Tim P

    Jan 18 Pre-Release Testers, Xojo Pro

    https://www.dropbox.com/s/l8xkihmljyku0f8/check.xojo_binary_project?dl=1
    Tada!

    Subclassed ignorable checkbox, and tester page to get really excited about it.

  11. Tim P

    Jan 18 Pre-Release Testers, Xojo Pro

    And of course, 15 minutes later I realize I used the wrong "pique / peak"

  12. Tom D

    Jan 18 Pre-Release Testers, Xojo Pro

    This is AWESOME Tim! I know I'm not the only one that will be using this . Thanks so much!

    Here, let me pique your interest again...
    Can I assume that the same approach will work with a Radio Button subclass, (since I haven't tied it yet)? I suppose this JavaScipt code needs to point to the radio button control type or will "_box" work for a Radio Button too?

    ExecuteJavaScript("document.getElementById('" + me.ControlID + "_box').setAttribute('onclick', '" + sOnClickAction + "');")
  13. Tim P

    Jan 18 Pre-Release Testers, Xojo Pro

    The _box came from looking at the source for a checkbox on the page. Turns out, Checkbox is encased in a table to hold the label in place. Maybe it was implemented before the current standards, but it turns out the actual checkbox is ControlID_box and the label is ControlID_caption.

    To pull off a similar thing for Radio Button, you'd have to look at the source of that and disable things appropriately. I have a pile of things to do today, so I won't be able to look into that right now. If you would like my tutorial video on how to inspect web apps and do javascript injections, shoot me an email or PM (I can't find the post, but I know where the video file is). Depending on your HTML knowledge (read: Googling skillz) you might be able to figure it out yourself :)

    And because I know they would like me to point it out:
    This subclass uses undocumented stuff from the framework, do not file bug reports if future updates to Xojo break this subclass.

  14. Tom D

    Jan 18 Pre-Release Testers, Xojo Pro

    Thanks Tim. You gave me enough clues I think I can figure it out without the video but I'd like the video anyway. I'll send you my email address in a PM.

  15. 4 weeks ago

    Tom D

    Jan 26 Pre-Release Testers, Xojo Pro

    Here is a link to both an ignorable WebCheckbox and an ignorable WedRadioButton
    ignorable_check_radio

    I've been unsuccessful doing the same thing with a WebPopupMenu since it isn't a Xojo Control but a standard web control and ignores the onclick return false property when I set it.

or Sign Up to reply!