|
|
@ -1,7 +1,7 @@
|
|
|
|
define(['../app', 'angular'], function (app, angular) {
|
|
|
|
define(['../app', 'angular'], function (app, angular) {
|
|
|
|
'use strict';
|
|
|
|
'use strict';
|
|
|
|
app.directive('ngInputName', function () {
|
|
|
|
app.directive('ngInputName', function () {
|
|
|
|
let myNameError = "myName directive error: "
|
|
|
|
let myNameError = "ngInputName directive error: "
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
restrict: 'A', // Declares an Attributes Directive.
|
|
|
|
restrict: 'A', // Declares an Attributes Directive.
|
|
|
@ -15,40 +15,22 @@ define(['../app', 'angular'], function (app, angular) {
|
|
|
|
// check myName input for proper formatting ex. something/something
|
|
|
|
// check myName input for proper formatting ex. something/something
|
|
|
|
checkInputFormat(attrs);
|
|
|
|
checkInputFormat(attrs);
|
|
|
|
|
|
|
|
|
|
|
|
let inputName = attrs.myName.match('^\\w+').pop(); // match upto '/'
|
|
|
|
let inputName = attrs.ngInputName; // match upto '/'
|
|
|
|
assignInputNameToInputModel(inputName, ngModel);
|
|
|
|
assignInputNameToInputModel(inputName, ngModel);
|
|
|
|
|
|
|
|
|
|
|
|
let formName = attrs.myName.match('\\w+$').pop(); // match after '/'
|
|
|
|
|
|
|
|
findForm(formName, ngModel, scope);
|
|
|
|
|
|
|
|
} // end link
|
|
|
|
} // end link
|
|
|
|
} // end return
|
|
|
|
} // end return
|
|
|
|
|
|
|
|
|
|
|
|
function checkInputFormat(attrs) {
|
|
|
|
function checkInputFormat(attrs) {
|
|
|
|
if (!/\w\/\w/.test(attrs.rsName)) {
|
|
|
|
if (!/\w/.test(attrs.ngInputName)) {
|
|
|
|
throw myNameError + "Formatting should be \"inputName/formName\" but is " + attrs.rsName
|
|
|
|
throw myNameError + "Formatting should be \"inputName\" but is " + attrs.ngInputName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function assignInputNameToInputModel(inputName, ngModel) {
|
|
|
|
function assignInputNameToInputModel(inputName, ngModel) {
|
|
|
|
ngModel.$name = inputName
|
|
|
|
ngModel.$name = inputName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function addInputNameToForm(formName, ngModel, scope) {
|
|
|
|
|
|
|
|
scope[formName][ngModel.$name] = ngModel;
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function findForm(formName, ngModel, scope) {
|
|
|
|
|
|
|
|
if (!scope) { // ran out of scope before finding scope[formName]
|
|
|
|
|
|
|
|
throw myNameError + "<Form> element named " + formName + " could not be found."
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (formName in scope) { // found scope[formName]
|
|
|
|
|
|
|
|
addInputNameToForm(formName, ngModel, scope)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
findForm(formName, ngModel, scope.$parent) // recursively search through $parent scopes
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|