Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Initial state of a ui-date control is dirty (ng-dirty) causing the form state to be dirty as well #158

Open
cs-NET opened this issue Mar 7, 2016 · 6 comments

Comments

@cs-NET
Copy link

cs-NET commented Mar 7, 2016

When you add ui-date directive to an input control the initial state of the control is dirty causing the form to be dirty as well. The control should only be dirty when the user changes the value.

https://plnkr.co/edit/QaM7f8uOn4mm11JiYAwr

@cs-NET
Copy link
Author

cs-NET commented Mar 7, 2016

I have tracked it down to the following code

          if (controller) {
            controller.$render();
            // Update the model with the value from the datepicker after parsed
            setVal(true); // *** this causes control to become dirty *** 
          }

@alexanderchan
Copy link
Contributor

Thanks for tracking that down, I will not have much time to update this so PRs are welcome.

@cs-NET
Copy link
Author

cs-NET commented Mar 11, 2016

@alexanderchan I understand and will see if I can get to it next week

@deggesim
Copy link

+1

If I add controller.$setPristine(); after setVal(true); it seems to work.

Too simple?
`

@zzsoszz
Copy link

zzsoszz commented Aug 25, 2016

can you guys fix it ?

@rbarinov
Copy link

rbarinov commented Dec 10, 2016

You can just add after lines:

	        if (controller) {
	          controller.$render();
	          // Update the model with the value from the datepicker after parsed
	          setVal(true);
	          controller.$setPristine();

additional code to set form $dirty field to false

	          if (controller.$$parentForm) {
	          	var anyOther = false;
		        for (var key in controller.$$parentForm) {
		        	if (key.indexOf('$') != 0) {
		        		var siblingController = controller.$$parentForm[key];

		        		if (siblingController.$dirty) {
		        			anyOther = true;
		        			break;
		        		}
		        	}
		        }

		        if (!anyOther) {
		          controller.$$parentForm.$setPristine()
		        }
		      }

faustimetal pushed a commit to Recras/ui-date that referenced this issue Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants