Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

mdTextFloat: input not updating dirty and pristine #687

Closed
ajberasategui opened this issue Nov 18, 2014 · 6 comments
Closed

mdTextFloat: input not updating dirty and pristine #687

ajberasategui opened this issue Nov 18, 2014 · 6 comments

Comments

@ajberasategui
Copy link

Hi,
I'm experimenting with md-text-float inputs and validations.

Basically, validation is not working.

I'm inspecting the component state and found that $dirty neither $pristine properties are being updated when using the input.

You can see here that even when the viewValue has been populated, $dirty and $pristine are not updated.

{"$viewValue":"Agustin","$modelValue":"Agustin","$validators":{},"$asyncValidators":{},"$parsers":[],"$formatters":[],"$viewChangeListeners":[],"$untouched":true,"$touched":false,"$pristine":true,"$dirty":false,"$valid":true,"$invalid":false,"$error":{},"$name":"name","$options":null}```
@ThomasBurleson
Copy link
Contributor

We are aware of these issues with md-text-float; and provide improvements in 0.7.0

@ajberasategui
Copy link
Author

Ok thank you!

@ericrini
Copy link

ericrini commented Dec 2, 2014

I think having md-input-float template out so much HTML is a bad pattern, let me explain my reasons.

<md-input-float ng-required="true"></md-input-float>

When adding standardized Angular attribute directives like ng-required they will need to be copied from the "md-input-group" onto the "input" element. This necessarily creates a lot of complex scope transformations (as the current code reflects in managing the ng-model attribute) and prevents users from defining custom attribute directives that will be compatible with "md-text-float". Additionally, the user might want to put additional content into the md-input-group (for example a validation message), so even if you could make the attribute copying problem fully dynamic it would still be problematic for this reason.

What I want to propose is making md-input-group and md-text-float separate directives.

<md-input-group>
    <md-input-float ng-required="true"></md-input-float>
</md-input-group>

This makes things a LOT more flexible. For example I can add standard Angular attribute directives to "md-input-float" and they will just work. It can still insert a label in the directive compilation, as users are not likely to need to enhance the label tag and abstracting the accessibility concerns is nice.

For additional improvements consider this pattern.

<md-form name="formName">
    <md-input-group name="inputName">
        <md-input-float ng-required="true" ng-pattern="/.*/"></md-input-float>
        <md-validator type="required">Enter something.</md-validator>
        <md-validator type="pattern">Still not right.</md-validator>
    </md-input-group>
</md-form>

This is an example where the user wants to add more to the input-group than a form element. The "md-validator" elements can communicate with the "md-input-group" and "md-form" to determine the name of the field. For example "formName.inputName.$error.required". This creates nice abstraction from having such expressions in the HTML template.

If you guys agree with these ideas, I'd be happy to prepare a pull request.

@ngraef
Copy link
Contributor

ngraef commented Dec 4, 2014

@ThomasBurleson are parsers and formatters for md-text-float included in this issue, or should I file a separate bug?

@ThomasBurleson ThomasBurleson changed the title md-text-float input not updating dirty and pristine mdTextFloat: input not updating dirty and pristine Dec 4, 2014
@ThomasBurleson
Copy link
Contributor

@ngraef - Let's see what the 0.7 refactor provides first. Can you provide a code sample of what you are looking for ?

@ngraef
Copy link
Contributor

ngraef commented Dec 4, 2014

Sure, here's a sample CodePen with a parser and formatter on a custom directive. Basically, the directive on md-text-float needs to be copied to the input element in the template.

@ajoslin ajoslin closed this as completed in 60fcd6f Jan 8, 2015
kashyapkaki pushed a commit to kashyapkaki/material that referenced this issue May 10, 2023
…ar#705)

Fixes angular#686 ,closes angular#687, fixes angular#550

- fix docs-api layouts to work down to 360px width
  - fixes Observers, Accessibility, Drag and Drop, Platform, and Overlay layouts
- fix DeprecatedconnectedTo to Deprecated connectedTo display issue
- update footer copyright
- fix exception trying to unsubscribe to undefined routeParamSubscription
- change how sidenav is closed on mobile after selecting a nav item
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants