Santanu Santanu - 2 months ago 12
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..radio buttons are used for show/hide a textbox1..my problem is that after selecting radio buttons textbox1 is hiding..i have added a validation on button ng-click..it 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

$("#txtto").hide();


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

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">
Comments