Solved

When hiding a field, I'd like to clear the field...


Badge +5

... w/o having to write a chunk of JS code each time. Is there something built into the Rules Engine to clear a field when it is hidden by a rule? I've searched the Nintex Connect Community for hours happy.png

 

Why would I want to do this you ask?

If a form user fills in a field that becomes irrelevant and is hidden, why would I want to store the irrelevant data?

 

Don't you just hate people who answer a question with a question?

 

I've written Custom JS to take care of it, but am hoping there is something built in. A function/method, etc.

 

Thanks mis amigos!

icon

Best answer by billr 12 June 2017, 16:36

View original

14 replies

Badge +7

Hi, 

If you aim to save empty value once field is hidden, add a calculated value connected to the same SP list column as per the fiel and set its visibility rule to the opposite of the field. Keep the calculated value empty so that once field is hidden, calculated value is shown and save empty value to SP list connected column.

*- Make sure to work on visibility from control settings (Expression) so HTML of the field/calculated value is totally removed from the page and thus no save conflict will happen.

Regards,

Userlevel 4
Badge +12

Really like this tip but the visibility expression doesn't allow to reference named controls. If I'd use a checkbox to hide the first control I can't check the same checkbox in the visibility expression, right? Or do I miss something?

Badge +5

No intention on saving an empty value one the field is hidden. Why would I do that? I find this answer somewhat strange in that my question had nothing about saving. I asked if there was something built in to clear the field upon being hidden.

Perhaps a little more detail will help. :)

I have a drop down.

In the drop down there is one item that triggers a field to be unhidden.

If for some reason a form user should fill this field in with data and then decide to change their drop down choice, hidding the field they just filled in, I want it to be cleared. The data has become irrelivent as the drop down choice has changed.

I clear the field using javascript now. Works fine. Just wondered why there wouldn't be an option to clear the filed once it is hidden. Thus preventing the capture of irrelivent data.

As I read my response, I wonder if hidden values are even saved, hmmmmm. I'm gonna do some testing...

Userlevel 5
Badge +14

unfortunatelly, there is not anything OOTB that would clear hidden controls.

only available option is javascript.

and yes, once hidden controls are connected to list fields they will be saved (sometimes that's very useful ...)

Badge +5

Just tested and the outcome is what I expected.

I selected the choice in the dropdown that shows the field

I filled in the field

Change my choice in the dropdown (thus hiding the field)

Submitted the form

Filed value was submitted

Maybe I'm out on a limb here, but that is not desirable behavior.

If there is nothing built in, I will stick with my custom JavaScript solution.

Badge +5

Ya, I see where it could be useful (Tabs, Wizards, etc.), however, an option in the field settings would allow either behavior or a method in the Rules Builder.

Oh, well, worth the ask.

Thanks all!

Userlevel 5
Badge +14

I understand you haven't got an answer you expected, but just to close the topic could you mark one of the posts as correct answer?

Badge +11

would be perfect if you do share your solution to this matter?

I also have 3 choices whereby 2 of them are hidden, depending which option is selected.

If you preselect an option, the value remain the same even if you change to a different option.

How can I clear the selected option IF it has been changed .... ??

Badge +2

Bill Rishsew Could you share you JS that you use to do this? This is exactly what I am looking for.

Thanks

Badge +5

Sure, let me see if I can dig it out

I used it in one instance out of hundreds of forms I've built since this post.

TTYL

Badge +5

Did some digging, not enough time in the day
Didn't find what/where I did what I said I did or if I even kept it.

Tried a bit of experimenting and this is what I have come up with.

1. First, you will need to add a JS Name to each of the columns you want to check and/or clear.

2. Create or take advantage of some trigger. Say, a drop down onChange event or a button Click event.

3. When triggered, check each of the controls, that are 'hidden' and clear the content ( .val() ).

e.g. (very crude, but hopefully helpful)

NWF$(document).ready(function () {

   NWF$('#' + checkboxYes).on('click', function () {
      if( NWF$('#' + txtSubmitted).is(':hidden') == true ) {
         NWF$('#' + txtSubmitted).val('');
      }
   });
});

Hope it helps.

Gotta run and do about a thousand++ things before they unlock my cage

Badge +2

Thank you!

Badge +3

I don't think this should be marked completed or answered.  I need this functionality in responsive, and since the solution relies upon custom JS, it's a workaround, not a solution.

Badge +3

We're pushing 2 years here, and still no solution?  As OP stated, the expected and desirable behavior is for the field that gets hidden to be cleared upon hiding.  I could see a use-case for not clearing, but that should be a configurable option, not the default.  And certainly not a situation where you can't resolve the non-desirable behavior.

Reply