Santanu Santanu - 1 year ago 94
jQuery Question

how to stop validation on a particular textbox after hiding this textbox using angularjs

i have there textbox and one submit button..and two radio buttons are used for show/hide a problem is that after selecting radio buttons textbox1 is hiding..i have added a validation on button is working fine..but after hiding the textbox the validation is still working if i dont put any data in textbox1..
my code is given below..

<form class="form-horizontal" name="myForm" method="get">
<asp:TextBox ID="txtto" runat="server" TextMode="Email" required ng-model="EmailID" ></asp:TextBox>
<asp:TextBox ID="txtsubject" runat="server" ng-model="Subject" required></asp:TextBox>
<asp:TextBox ID="editor" runat="server" TextMode="MultiLine" ng-model="Message" Rows="10" required></asp:TextBox>

<button ng-click="myform.$valid && SendMailData()" id="sendmail" class="btn btn-sm btn-primary" data-toggle="tooltip" data-placement="top" title="Send">Send</button>

i have show hide the textboxes using this jquery function


my problem is that validation is still working after hiding the textboxes...
can anyone help me please????i want to stop validation for this textbox after hiding this textbox.......

Answer Source

Use ng-if instead of $("#txtto").hide();

<asp:TextBox ID="txtto" runat="server" TextMode="Email" required  ng-model="EmailID" ng-if="radioValue == 'showText'"></asp:TextBox>

Where expression is your angularjs expression to show/hide the tag.

Could apply below logic::

<input type="radio" ng-model="radioValue" ng-value="showText">
<input type="radio" ng-model="radioValue" ng-value="HideText">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download