Not applicable

How make sure "cleared" lookup value from form is not saved

Jump to solution

Hi,

 

My SharePoint list has 2 columns:

End user name (lookup field)

End user name manual (text field)

 

It is required that one of them has a value (not both of them).

So either End user name should have a value, either End user name manual.

 

This is an extract from my form:

 

22-10-2015 17-35-46.png

 

Note: the CONT_IDS_CLEAN CORRECT_ANSWERS DISC_IDS_CLEAN content_ids curl_test.sh disc_ids_qready discussions queries questions_set.log test test_CID test_body are just labels (not coming from requirements on the list).

 

Default the End user name dropdown is enabled, the text field (bottom) disabled.

When I don't find the name in the list, I check the checkbox to enable the bottom textfield and disable + clear the top dropdown.

 

Before:

22-10-2015 17-40-54.png

After:

22-10-2015 17-41-10.png

This is done with the following javascript code:

 

var EnduserNameNotAvailable = NWF$('#' + varEnduserNameNotAvailable);      

 

EnduserNameNotAvailable.change(function()

 

{if (EnduserNameNotAvailable.prop('checked') == true)

{ NWF$('#' + varEnduserName).val("");

}

else

{ NWF$('#' + varEnduserNameManual).val("");

}

}

);

 

As you can see the change on the checkbox triggers the code to set the lookup value to "".

 

However, it seems that the lookup is only cleared "superficially". When I save the form the previously selected value "BP" is still saved in the list, even though the form didn't show it anymore.

 

In summary: when I select the default value of the dropdown manually ("Please select a value...") then no value is save on the column. When I use javascript code to select the default value then -unexpectedly- a previously selected value is saved.

 

How should I prevent that value from being saved? Or how can I do a "real" clear?

 

Thanks in advance for suggesting a solution.

 

Wim

0 Kudos
Reply
3 Replies
Not applicable

Re: How make sure "cleared" lookup value from form is not saved

Jump to solution

Try NWF$('#' + varEnduserName).val("").change(); see if it works.

0 Kudos
Reply
Not applicable

Re: How make sure "cleared" lookup value from form is not saved

Jump to solution

Stephen, thanks for the tip but unfortunately no positive result.

Any other suggestions?

0 Kudos
Reply
Not applicable

Re: How make sure "cleared" lookup value from form is not saved

Jump to solution

Found the solution:

NWF$('#' + varEnduserName).val("").

To be replaced by

EnduserName = NWF$('#' + varEnduserName +  ' option:eq("")');

EnduserValue = EnduserName.val();

EnduserName.attr('selected','selected');

NWF$('#' + varEnduserName).parent().find('input').val(EnduserValue);

(solution based on solution in this thread:Javascript/Jquery assigned list lookup value can not be saved )

View solution in original post

0 Kudos
Reply