最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to validate the form using angularjs when the name field has .(dot) in it? - Stack Overflow

programmeradmin2浏览0评论

In my form I have a input tag with name="Customer.Firstname" so when i refer to name value in angularjs its taking only customer as the value and .Firstname is going unidentified. Here is my code:

<label class="label_block" ng-hide="ApplicantDetails.Customer.FirstName.$error.required || ApplicantDetails.Customer.FirstName.$error.pattern">FirstName</label>
<span class="clearable">
    <input class="textbox"  type="text" name="Customer.FirstName" ng-model="Customer.FirstName" ng-init="Customer.FirstName='@Model.Customer.FirstName'" value="@Model.Customer.FirstName" ng-pattern="/^([a-zA-Z-']{1,30})$/" required="required"/>
</span>

Here am trying to hide the label when the textbox is empty.How can i do that?

In my form I have a input tag with name="Customer.Firstname" so when i refer to name value in angularjs its taking only customer as the value and .Firstname is going unidentified. Here is my code:

<label class="label_block" ng-hide="ApplicantDetails.Customer.FirstName.$error.required || ApplicantDetails.Customer.FirstName.$error.pattern">FirstName</label>
<span class="clearable">
    <input class="textbox"  type="text" name="Customer.FirstName" ng-model="Customer.FirstName" ng-init="Customer.FirstName='@Model.Customer.FirstName'" value="@Model.Customer.FirstName" ng-pattern="/^([a-zA-Z-']{1,30})$/" required="required"/>
</span>

Here am trying to hide the label when the textbox is empty.How can i do that?

Share Improve this question edited Oct 16, 2013 at 12:21 Halcyon 57.7k10 gold badges92 silver badges130 bronze badges asked Oct 16, 2013 at 12:20 PaRsHPaRsH 1,3205 gold badges29 silver badges59 bronze badges 2
  • You can give a different name than the ng-model. It could be CustomerFirstName. Or maybe use thé array notation like Form['Customer.FirstName'] – jpmorin Commented Oct 16, 2013 at 12:27
  • possible duplicate of JavaScript property access: dot notation vs. brackets? – Stewie Commented Oct 16, 2013 at 12:35
Add a ment  | 

1 Answer 1

Reset to default 11

You can use bracket notation to access keys with dot

<label class="label_block" ng-hide="ApplicantDetails['Customer.FirstName'].$error.required || ApplicantDetails['Customer.FirstName'].$error.pattern">FirstName</label>

Demo: Fiddle

This can be rewritten as

<label class="label_block" ng-show="ApplicantDetails['Customer.FirstName'].$valid">FirstName</label>

Demo: Fiddle

发布评论

评论列表(0)

  1. 暂无评论