Xamarin.Forms 101: Data Binding | The Xamarin Show
January 10, 2019
@mydock365 Dock 365 Inc.
January 10, 2019

Show/Hide Script on List Edit Form doesn’t fire automatically on Page Load

I have a simple show/hide js code in a Content Editor in a List Edit form. The form has (3) fields:

  • field name: Food (Choice)
  • field name: txtName (Text)
  • field name: txtToppings (Text)

When ‘Pizza’ is selected as the value for the “Food” field, both ‘the txtToppings’ and ‘txtName’ are shown. The code works when a user changes the value, but the show/hide behaviors are not implemented on a new page load. Even in the value for the “Food” field is set to ‘Pizza’, neither the ‘txtToppings’ nor the ‘txtName’ fields are shown when reopening the item’s edit form. Instead, the user winds up having to manually re-select a value for the “Food” field in order to activate the show/hide behavior. Is there an issue with my code? I’ve looked everywhere for a solution, but I can’t seem to make this happen. Any help would be appreciated!

<script type="text/javascript"> $(document).ready(function(){ alert('onload'); //Hides both fields on load $("nobr:contains('txtName')").parent('h3').parent('td').parent('tr').hide(); $("nobr:contains('txtToppings')").parent('h3').parent('td').parent('tr').hide(); //Show/hide columns based on Choice Field 'Food' Selection $("select[title='Food']").change(function() { if ($("select[title='Food']").val() == "Pizza") { //If the value of field:Food is "Pizza", SHOW both fields $('nobr:contains("txtName")').closest('tr').show(); $('nobr:contains("txtToppings")').closest('tr').show(); } else if ($("select[title='Food']").val() == "BBQ") { //If the value of field:Food is "BBQ" $('nobr:contains("txtName")').closest('tr').show(); $('nobr:contains("txtToppings")').closest('tr').hide(); } else { //If the value of **Food** column is anything but "Pizza" $('nobr:contains("txtName")').closest('tr').show(); $('nobr:contains("txtToppings")').closest('tr').hide(); } }); }); </script> 

submitted by /u/Quadaliacha
[link] [comments]

News Reporter
News Reporter
Head of Operations (Banking), Director IT Governance, Teamlead Microsoft, Service Delivery Manager. Interested in Office 365, LAMP, IT Security and much more!