Results 1 to 5 of 5

Thread: Enable/Disable OKI button on dialog based on form content?

  1. #1

    Default 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. #2

    Default

    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;
                }

  3. #3
    Join Date
    Sep 2004
    Location
    Ghent, Belgium
    Posts
    224

    Default

    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

  4. #4

    Default

    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

  5. #5
    Join Date
    Sep 2004
    Location
    Ghent, Belgium
    Posts
    224

    Default

    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

Similar Threads

  1. Replies: 3
    Last Post: Jun 8th, 2010, 03:27 AM
  2. Replies: 9
    Last Post: May 4th, 2006, 09:53 AM
  3. Replies: 13
    Last Post: Dec 3rd, 2004, 10:19 AM
  4. Replies: 2
    Last Post: Nov 12th, 2004, 06:17 AM
  5. Form field behavior based on user profile
    By diegum in forum Security
    Replies: 1
    Last Post: Sep 2nd, 2004, 04:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •