Date Validation in Repeating section - InfoPath Dev
in

InfoPath Dev

Date Validation in Repeating section

Last post 08-30-2012 07:42 AM by Hilary Stoupa. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 08-27-2012 12:08 PM

    Date Validation in Repeating section

    Hello, I have a date control in a repeating section that I want to prevent the forum from being submitted if the date entered is 60 days less than the current date. Currently I have a rule where I check to see if the date entered is less than addDays(today(), -60) which seems to function OK. However, if i first enter a valid date in the repeating section, add a second and change the date to 3 years in the past and submit it throws an error seeming to stop the form but the formatting rules on the button seem to fire but the actions do not. So what ends up happening is the form is stopped form submitting like i want but now the button disappears as well as a few other things on the form. One last challenge it seemed with this too is when I have the rule on the date control, initially the value is blank. that fails validation right away even if there are no items to enter. It kind of stinks that I have to set a default date as it is confusing to the user. I would like it to be that if the field is empty ignore validation else validate the field. Can this be done? So how does one do this? Thanks,
  • 08-28-2012 07:19 AM In reply to

    Re: Date Validation in Repeating section

    Hi,

    I don't think I understood the first question.

    For your second question, all you need is to add a second condition. So instead of having the rule execute when DateEntered < addDays(today(),-60) add a second condition such that DateEntered "is not blank". This will prevent the form from throwing a validation error before the field is filled out.

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


  • 08-28-2012 09:16 AM In reply to

    Re: Date Validation in Repeating section

    Thank you for the reply. Let me see if i can explain this better. The date is in a repeater so I can enter more then one of these. The only rule on the date is a validation rule of the following: DateEntered is less than addDays(today(),-60). This seems to work fine. The submit button I have tired disabling the control where DateEntered is less than addDays(today(),-60) but that doesn't seem to function for some reason and I don't know if this is due to the repeater possibly? This is what I enter. I first enter a valid date. I add another date and set that to be something outside the range of my formula. The validation seems to work as the box will be set with a red border. When I click the submit button just to see what happens I am first setting a status flag and then submitting the form to sharepoint. When I submit it i then get a validation error which is correct. However, the flag i mentioned that gets set first now has done some things to my form that are watching this status and I do not want that to occur. If there are validation errors I don't want that flag to get set. If i first submit the form and then set the flag that will not work as it is saving it after the submission so when I go to review it those changes that I want to occur do not as the saved form does not contain that flag as it was set prior. Does this make a little more sense? I am confused why the disabling of the submit button does not function and wondering if it is really due to the repeater possibly and how behind the scenes, those date values are stored
  • 08-28-2012 10:17 AM In reply to

    Re: Date Validation in Repeating section

    First of all I am not sure why my text gets all jammed up into one paragraph so my apologies there. I did some additional testing simply adding a date picker control outside of the repeating table and this seems to function a s I would expect. It also seems OK with the first item in the repeating table. When additional items get added that violate my validation rules they do not disable the submit button. Is there any way around this?
  • 08-28-2012 11:19 AM In reply to

    Re: Date Validation in Repeating section

    The validation rule needs to go on the date field in the repeating table itself. The first condition should be if the field is not blank (to prevent false errors).

    Then add your second validation rule.

    InfoPath won't let users submit if there are validation errors in the form. However, based on this description, it sounds like you may have some other rules that are executing even if the form cannot submit. You may need to add some logic to count the instances where the date field is not valid.

    Hilary Stoupa

  • 08-28-2012 12:28 PM In reply to

    Re: Date Validation in Repeating section

    Thanks for the reply. I am still unclear on how to proceed. I have the condition that it is not blank on the date field and that seems to function without issue. What I need to happen though is not allow them to even click the submit button I think until all the validation errors are fixed. You are correct that when the submit button is clicked the first thing that happens is a status flag gets set to say the form was submitted (based on this the submit button goes away and some sections then get displayed. These are simply checking the field to see if it is equal to something and if so turn stuff off or on). The next action is then to submit the form to the sharepoint list where it then fails. However my that flag is still set so the stuff i should not yet see is on and the submit button, for example is now hidden but the form did not really submit. Is there a better place to flip this flag or to turn things off or on based on a successful submission?
  • 08-29-2012 11:39 AM In reply to

    Re: Date Validation in Repeating section

    Hello, I am wondering if this issue is in fact a bug as I tried it on another form with the same result. It seems that if you put validation on a field within a repeating table the validation expression only looks at the first entry. Any other entry is ignored. So the test I did was to add a repeating table and a single date control and a button. on the button I simply check to see if the date is outside of 60 days in the past and if so i want to disable it. The first entry will enable and disable the button however, when I change the second or third entry it does not. Is it possible to actually do this and is this a bug perhaps? Thanks again for all the help.
  • 08-29-2012 12:04 PM In reply to

    Re: Date Validation in Repeating section

    I am having such a hard time understanding what you are doing & trying to do.

    Validation works in repeating tables. See the attached sample - if the data selected in any row is greater than today less 60 days, it is invalid.

    My earlier suggestion was you might want to count all the valid dates in the form before enabling your submit button - I've added this logic in the sample form.

     

    Hilary Stoupa

  • 08-29-2012 05:08 PM In reply to

    Re: Date Validation in Repeating section

    Hilary, Thanks for sticking with me. I am pretty new to this. I understand now I think what you are attempting and I think you are right that that might work. However, how did you build the expression? Thanks again.
  • 08-29-2012 05:42 PM In reply to

    Re: Date Validation in Repeating section

    Hi Hilary I got it working. I thought you were creating the expression through some funky utility or something along those lines but once I got that out of my head I was able to get it working. Thanks for pointing me in the right direction and sticking with me once again. For anyone else, here is what it ended up being: count(my:CHARGEABLE/my:Expenses/my:dtDateOfTravel[msxsl:string-compare(., xdDate:AddDays(xdDate:Today(), -60))
  • 08-30-2012 07:42 AM In reply to

    Re: Date Validation in Repeating section

    Hey, wonderful, glad you figured it out!

    Hilary Stoupa

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