mirror of
https://github.com/nasa/openmct.git
synced 2025-03-11 06:54:01 +00:00
[Forms] Support patterns
Support patterns for text fields, using the ng-pattern directive. WTD-530.
This commit is contained in:
parent
aaa0ff768d
commit
354327accc
@ -3,6 +3,7 @@
|
||||
<input type="text"
|
||||
ng-required="ngRequired"
|
||||
ng-model="ngModel[field]"
|
||||
ng-pattern="ngPattern"
|
||||
name="mctControl">
|
||||
</span>
|
||||
</span>
|
||||
|
@ -23,23 +23,26 @@
|
||||
</div>
|
||||
<div class='controls'>
|
||||
<div class="wrapper" ng-if="row.control">
|
||||
|
||||
<mct-control key="row.control"
|
||||
ng-model="ngModel"
|
||||
ng-required="row.required"
|
||||
options="row.options"
|
||||
structure="row"
|
||||
field="row.key">
|
||||
</mct-control>
|
||||
<mct-control key="row.control"
|
||||
ng-model="ngModel"
|
||||
ng-required="row.required"
|
||||
ng-pattern="getRegExp(row.pattern)"
|
||||
options="row.options"
|
||||
structure="row"
|
||||
field="row.key">
|
||||
</mct-control>
|
||||
</div>
|
||||
<div ng-repeat="item in row.items" class="validates">
|
||||
<ng-form name="mctFormInner">
|
||||
<ng-form name="mctFormItem">
|
||||
<mct-control key="item.control"
|
||||
ng-model="ngModel"
|
||||
ng-required="item.required"
|
||||
ng-pattern="getRegExp(item.pattern)"
|
||||
options="item.options"
|
||||
structure="item">
|
||||
structure="row"
|
||||
field="item.key">
|
||||
</mct-control>
|
||||
{{item.name}}
|
||||
</ng-form>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -8,6 +8,8 @@ define(
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
var MATCH_ALL = /^.*$/;
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
@ -20,18 +22,47 @@ define(
|
||||
].join("/");
|
||||
|
||||
function controller($scope) {
|
||||
var regexps = [],
|
||||
matchAll = /.*/;
|
||||
|
||||
// ng-pattern seems to want a RegExp, and not a
|
||||
// string (despite what documentation says) but
|
||||
// we want form structure to be JSON-expressible,
|
||||
// so we make RegExp's from strings as-needed
|
||||
function getRegExp(pattern) {
|
||||
// If undefined, don't apply a pattern
|
||||
if (!pattern) {
|
||||
return MATCH_ALL;
|
||||
}
|
||||
|
||||
// Just echo if it's already a regexp
|
||||
if (pattern instanceof RegExp) {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
// Otherwise, assume a string
|
||||
// Cache for easy lookup later (so we don't
|
||||
// creat a new RegExp every digest cycle)
|
||||
if (!regexps[pattern]) {
|
||||
regexps[pattern] = new RegExp(pattern);
|
||||
}
|
||||
|
||||
return regexps[pattern];
|
||||
}
|
||||
|
||||
$scope.$watch("mctForm", function (mctForm) {
|
||||
console.log(JSON.stringify(mctForm));
|
||||
if ($scope.name) {
|
||||
$scope.$parent[$scope.name] = mctForm;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.getRegExp = getRegExp;
|
||||
}
|
||||
|
||||
return {
|
||||
restrict: "E",
|
||||
templateUrl: templatePath,
|
||||
link: controller,
|
||||
controller: controller,
|
||||
scope: {
|
||||
structure: "=",
|
||||
ngModel: "=",
|
||||
|
Loading…
x
Reference in New Issue
Block a user