AngularJS - 从表单验证/脏中排除字段

时间:2017-03-23 09:48:51

标签: javascript angularjs html5 forms

checkbox ng-form HTML5 form $state $pristine $dirty ignoreDirty ng-form HTML5 form <form name="mainForm" class="col-xs-10 form-validation" novalidate> <ng-form name="innerForm"> <div> <span>check my <span ng-if="vm.utils.mode!=='readonly'"> <input type="checkbox" ng-model="vm.utils.amalotSecond" class="secondYearCheckBox"> </span> </span> </div> </ng-form> <form> {@}} True\r\n False\r\n True False r'^[.]+|[\r]+|[\n]+(True\r\n)$'\r)。

我尝试使用import re sample_response = 'var0 = 0x00000001\r\nTrue\r\n' re_true = re.compile(r'^[.]+|[\r]+|[\n]+(True\r\n)$') print re_true.search(sample_response).group(0) # Will print out '\r' 指令 - Angular 1.2: Is it possible to exclude an input on form dirty checking?

和其他一些解决方案,import re sample_response = 'var0 = 0x00000001\r\nTrue\r\n' re_true = re.compile(r'(?<=(True\r\n))') print re_true.search(sample_response).group(0) # Will print out '' print re_true.search(sample_response).group(1) # Will print out 'True\r\n' for file in `git diff [start-sha] [end-sha] --name-only`; do echo -n "$file "; git log --pretty=short [start-sha] [end-sha] -- $file | /bin/grep commit | cut -b8- | head -n 1; done 内的static class Global { private static List<GridRows> _globalVar = new List<GridRows>(); public static void ResetGridData() { _globalVar = new List<GridRows>(); } public static GridRows SetRow { set { _globalVar.Add(value); } } public static List<GridRows> GetSetting { get { return _globalVar; } } public class GridRows { public string Cell_1 { get; set; } public string Cell_2 { get; set; } public string Cell_3 { get; set; } public string Cell_4 { get; set; } } } 无效,代码如下:

public partial class Form2 : Form
{
    public Form2()
    {
        //To reset our temporary store on load
        Global.ResetGridData();
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        //Send data from form 2 to form 1
        Form1 b = new Form1(dataGridView1.SelectedRows[0].Cells[2].Value.ToString(),
        dataGridView1.SelectedRows[0].Cells[3].Value.ToString(),
        dataGridView1.SelectedRows[0].Cells[4].Value.ToString(),
        dataGridView1.SelectedRows[0].Cells[5].Value.ToString());
        b.ShowDialog();

    }
}

1 个答案:

答案 0 :(得分:5)

您提供的ignoreDirty指令可以像demo fiddle一样正常工作。以下代码示例取自angular-1-2-is-it-possible-to-exclude-an-input-on-form-dirty-checking。还要尽量避免使用不符合HTML的嵌套表单。 form元素不能包含元素form。它会导致问题和错误,例如你正面临的那个。

视图

<div ng-controller="MyCtrl">
  <form name="test">
    Watching dirty: <input ng-model="name"  /><br />
    Ignoring dirty: <select ng-model="gender" ignore-dirty>
      <option>male</option>
      <option>female</option>
    </select><br />
    dirty: {{test.$dirty}}
  </form>
</div>

AngularJS应用程序

var myApp = angular.module('myApp',[]);

myApp.controller('MyCtrl', function ($scope) {
    $scope.name = 'Superhero';
});

myApp.directive('ignoreDirty', [function() {
    return {
    restrict: 'A',
    require: 'ngModel',
    link: function(scope, elm, attrs, ctrl) {
      ctrl.$setPristine = function() {};
      ctrl.$pristine = false;
    }
  }
}]);