Skip to content

Instantly share code, notes, and snippets.

@carbonrobot
Created October 27, 2015 01:33
Show Gist options
  • Save carbonrobot/dbeb9eda9c0fbd3a45bd to your computer and use it in GitHub Desktop.
Save carbonrobot/dbeb9eda9c0fbd3a45bd to your computer and use it in GitHub Desktop.
Set $touched to true on click of submit button
'use strict';
angular.module('app.default').directive('ckValidateOnClick', ckValidateOnClick);
function ckValidateOnClick($compile) {
return {
restrict: 'A',
require: '^form',
link: function compile(scope, element, attrs, form) {
var col = element.parent('form').find('[name]'),
parts = form.$name.split('.');
element.on('click', function () {
col.each(function (i, e) {
var ele = angular.element(e),
name = ele.attr('name');
scope[parts[0]][parts[1]][name]['$touched'] = true;
});
});
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment