Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(FormController): add $submitted $setSubmitted#8406

Closed
PatrickJS wants to merge 1 commit into
angular:masterfrom
PatrickJS:submitted
Closed

feat(FormController): add $submitted $setSubmitted#8406
PatrickJS wants to merge 1 commit into
angular:masterfrom
PatrickJS:submitted

Conversation

@PatrickJS
Copy link
Copy Markdown
Contributor

allowing $submitted on FormController allows the user more convenience when dealing with ngMessages for example
https://yearofmoo.github.io/ngMessages/

angular.module('yolo', ['ngMessages'])
.controller('exampleCtrl', function($scope) { 
    this.model = '';
    $scope.submitted = false;
    $scope.submit = function() {
      $scope.submitted = true;
    };
    $scope.interacted = function(field) {
      return $scope.submitted || field.$dirty;
    };
}
<form name="userForm">
  <input name="emailAddress" ng-model="ctrl.model">
  <div 
    ng-messages="userForm.emailAddress.$error" 
    ng-if="interacted(userForm.emailAddress)" 
    ng-messages-include="error-messages"
  ></div>
</form>

with $submitted would simply be

angular.module('yolo', ['ngMessages'])
.controller('exampleCtrl', function($scope) { 
    this.model = '';
}
<form name="userForm">
  <input name="emailAddress" ng-model="ctrl.model">
  <div 
    ng-messages="userForm.emailAddress.$error" 
    ng-if="userForm.$submitted || userForm.emailAddress.$dirty" 
    ng-messages-include="error-messages"
  ></div>
</form>

I can also add .ng-submitted class etc that would help for styles
I also added .ng-submitted to the form for styling input errors when the form is submitted and still dirty

@MehulATL
Copy link
Copy Markdown
Contributor

this is 💰

@Hendrixer
Copy link
Copy Markdown
Contributor

:neckbeard: can we haz that please?

@rodyhaddad
Copy link
Copy Markdown
Contributor

Great idea, and we agree it should become a thing.

There's already a PR implementing this feature: #8056 :-)

I'll close this for now, and move the other PR to the current milestone.

@rodyhaddad rodyhaddad closed this Jul 30, 2014
@PatrickJS
Copy link
Copy Markdown
Contributor Author

sweet

@PatrickJS PatrickJS deleted the submitted branch July 30, 2014 04:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants