Announcement Announcement Module
Collapse
No announcement yet.
Enable/Disable OKI button on dialog based on form content? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Enable/Disable OKI button on dialog based on form content?

    Folks,

    Im sure this can be done, Im not just seeing it yet tho....

    I have a titled dialog page with a form content.....with a text area

    Id like to be able to enable/disable the "OK" button on the dialog depending on whether the user has entered txt or not, ie an empty text area/null value is not allowed..

    Basically i guess I need to listen for text entered in the text area, and enable/disable the button appropriately..

    Any hints here, folks?


    Cheers


    Alan

  • #2
    FWIW, as i needed it fast....in my TitledApplicationDialog I did the following which works...tho Im sure its not the preferred way. I realise theres validation but the overlays for a TextArea dont appear to be coorect yet, as per a JIRA issue I remember reading....

    Code:
    protected JComponent createTitledDialogContentPane() {
                    setFinishEnabled(false);
                    JComponent component = form.getControl();
                    form.addFormValueChangeListener("tagEvent.description", new ValueChangeListener() {
                        public void valueChanged() {
                            String value = (String)form.getValue("tagEvent.description");
                            setFinishEnabled(null != value && value.length() > 0); 
                        }
                    });
                    return component;
                }

    Comment


    • #3
      You need to use rules based validation.

      Check the sample application for the PetClinicValidationRulesSource

      You'll have something like this:

      Code:
      public class MyRulesSource extends DefaultRulesSource {
      
          public MyRulesSource() {
              Rules rules = new Rules&#40;<FormObject>.class&#41;;
              rules.add&#40;"tagEvent.description", required&#40;&#41;&#41;;
          &#125;
      &#125;
      This will cause the ok button to be disabled as long as the tagEvent.description is not filled in,

      About the overlay thing, remove the OverlayValidationInterceptorFactory reference in the app context, or modify it so it won't intercept text areas

      hope this helps,

      Peter

      Comment


      • #4
        Thanks for the reply Peter, that clarifies matters greatly for me. Id already looked at the Rules stuff and made an incorrect assumption that if Id used it, I would have got the strange TextArea overlay problem, and basically didnt know how to get round that.

        I knew you chaps would have an elegant solution...

        Many thanks...btw Peter, how much do you think it would take to get the PageComponent and PageCOmponentListener hooks working correctly for views? ie opened/close/focus gained/lost. I f I had these I think I can live quite happily with the view management stuff as it is, whilst the project moves on..

        Regards

        Alan

        Comment


        • #5
          Many thanks...btw Peter, how much do you think it would take to get the PageComponent and PageCOmponentListener hooks working correctly for views? ie opened/close/focus gained/lost. I f I had these I think I can live quite happily with the view management stuff as it is, whilst the project moves on..
          I think I have the fix lying around here, I'll post it to the jira when I found it.

          Peter

          Comment

          Working...
          X