Sunday, January 16, 2011

Clear and then disable controls in infopath

This is simple for reading, but difficult to implement in infopath forms. To disable controls we have to use “Conditional Formatting” option of a control. To clear content of a control then we have to use “Rules” option of a control. But, the sequence of execution of these two causes some problems. Take below scenario.
I have a table and each row the first column contains a checkbox and all other 4 columns are having date field, textbox, drop down and date field respectively. Now, the logic should be this.
  1. The default state of checkbox is selected.
  2. When user enter some data in all other 4 fields and now he thought the row should not allowed to enter data then he deselect the checkbox. When user deselects then the first thing should happen is clear the content in all the 4 controls and then all controls should be disabled.
  3. When again user select the checkbox then the controls should be enabled.
This is what to be happen and the first trail when I tried to implement I did below things.
  1. On all other 4 controls I added a rule that when checkbox selected state is false then set the current field to empty.
  2. And then I added a conditional formatting on them to disable when the checkbox state is unchecked.
I did deploy them to SharePoint and when I tested, surprisingly they are not working as expected. The controls are going to disable state but not clearing content in them when I deselect the checkbox. And researched and found that the Rules are not executing. [Didn’t find the reason yet.] And then thought about for alternatives and came up with reverse way. That is, applying rule on the checkbox instead of other controls.
Earlier, I have applied rules on the each and every individual control which needs to be cleared based on checkbox state – Which doesn’t work. Now, I have applied the same logic but applied rule on the checkbox [As there are 4 controls, 4 times I have added set field to empty] and which is working like charm.
So the conclusion I want to tell to you is, when I apply conditional formatting and then rules something is causing problems in the sequence of execution. So, depends on what your control, rules needs to be executed apply the rules on that control only. That should work perfect.

4 comments:

  1. controls in path selection only.....

    ReplyDelete
  2. thanks for information..........

    ReplyDelete
  3. This helped me!! Thanks!! I had tried for about an hour until I found your post!!!

    ReplyDelete
  4. This helped me too!! Thanks!!

    ReplyDelete