Disable "cannot be blank" condition when control is hidden - InfoPath Dev
in

InfoPath Dev

Disable "cannot be blank" condition when control is hidden

Last post 03-15-2013 09:08 AM by kildonan500. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 03-31-2011 11:28 AM

    Disable "cannot be blank" condition when control is hidden

    I have a date picker control inside a section control.  The section control is hidden when another drop down list control selection equals a certain value.  I have "cannot be blank" checked on the date picker control

    The problem arises when the section control is hidden (and not needed).  The form won't submit because the date picker control is blank which it will be when it's hidden and thus not required.  Other than giving it a default date which would  deem the data validation moot, is it possible to override this data validation if the control isn't needed (is hidden)?

    One thing I've tried that isn't working is to remove "cannot be blank" check mark, then create a rule so that when the section is supposed to be hidden, set date picker value to a date that is acceptable. I did this by setting value of the date picker control to the value of another date picker control from the form. Data validation still stops it because the resulting value is blank. I've verifed the other  date picker control value is NOT blank. Both date picker data types are set to "Date and time (date Time)" and Format  is default:  Display the date like this: *3/14/2001, Display the time like this: (Do not display time).

    Rule example:

    Condition: dropdownlist = "Hide datepicker1 control"

    Action: Set a field's value: datepicker1 = datepicker2

     

    Datepicker 2 is a required field and while it will be blank when datepicker1 value it called, it will be filled by the time the form submit button is clicked.  It's a timing thing, isn't it?

     

     

     

     

  • 04-01-2011 06:23 AM In reply to

    Re: Disable "cannot be blank" condition when control is hidden

    I don't know how or if it's possible to dynamically remove/add the "cannot be blank" property, so I would recommend a different approach. Disable the submit button. So you'll have two possible scenarios for the Submit button:

    1. section is not hidden, therefore the date is required, therefore disable the Submit button until the date is entered.

    2. section is hidden, therefore the date is not required, therefore the Submit button will be enabled.

    Of course this means removing the "cannot be blank" requirement on the date picker control.

    Ernesto Machado
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™


  • 04-01-2011 09:54 AM In reply to

    Re: Disable "cannot be blank" condition when control is hidden

    Thanks Ernesto.  I hadn't considered disabling the submit button.

     

    I worked out a solution that is somewhat acceptable.  I went with my original plan to set date picker1 = date picker 2 if section control is hidden.  I set 2 rules in date picker 2 control;

    Rule 1 if section hidden and date picker 1 date is blank, set date picker1 = date picker2

    Rule 2 if section visible, set date picker 1 = " " //set date picker1 to blank so it starts out blank and data validation ("cannot be blank") still works - user is forced to set an original date.

     

    This might be a question for a new forum but the only problem is if a user selects section to be visible which requires they enter a value for date picker 1 AND they do, then changes their mind and reselects section to be hidden before submitting.  The date picker1 value doesn't change back to the default date in my rule. 

     

    How do I refresh the date picker1 settings if the condition which it relies upon changes? 

     

  • 04-01-2011 10:33 AM In reply to

    Re: Disable "cannot be blank" condition when control is hidden

    I solved my dilemna of refreshing.  I am quickly learning it matters what control you apply a rule to, to get the results you need.  My solution was to remove the rules I had placed on date picker 2 and move them to  dropdown list box control.  Now when a user changes their selection from drop down list, the hide/visible and corresponding dates/no dates are reflected accurately! Yeah.

  • 03-15-2013 09:08 AM In reply to

    Re: Disable "cannot be blank" condition when control is hidden

    I know this reply is probably not beneficial to the OP but for anybody coming across this post having done a google search heres my simple solution to the problem of validating hidden controls, instead of setting arbitrary dates/values to hidden fields:

    - Disable the "cannot be blank" checkbox on the date picker control
    - Instead add a validation rule to the date picker (or whatever other hidden field) whose condition is is the date picker cannot be blank AND the boolean which toggles whether the section is visible is true, is set to true. In this way the validation will only take place when the section is visible.
    - In the case of the original poster this may have meant creating a new boolean/field that is set to false by default, and turns true when the drop down value reached the selected value they desired. Then the validation would only take place when that boolean is true AND the field is blank.

    In this way you can accomplish requiring validation only when the field is visible. You cant directly set a rule on whether a field is hidden or not, but you can set a boolean that matches with/corresponds with whether the field/section/control is hidden or not. You just have to make sure they are in sync.

     

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.