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

feat(input): support multiple attribute for email #8987

Closed
wants to merge 2 commits into from
Closed

feat(input): support multiple attribute for email #8987

wants to merge 2 commits into from

Conversation

shahata
Copy link
Contributor

@shahata shahata commented Sep 9, 2014

Closes #8986

@shahata
Copy link
Contributor Author

shahata commented Sep 9, 2014

Closes #6032

@shahata
Copy link
Contributor Author

shahata commented Sep 9, 2014

Not sure if ng-model should expose an array in this case. Would be nice to hear someone's opinion about that...

return ctrl.$isEmpty(value) || EMAIL_REGEXP.test(value);
if (!ctrl.$isEmpty(value)) {
value = attr.multiple ? value.split(/\s*,\s*/) : [value];
for (var i = 0; i < value.length; i++) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really like to use Array.prototype.every here instead of this for loop. Since IE8 is no longer supported, can we do that?

@Narretz
Copy link
Contributor

Narretz commented Sep 9, 2014

Honestly, I'd love to have a more robust solution for this that works with all (text-based)-inputs similar to ngList (which exposes an array). I don't know what the HTML spec says about delimiters, supported input types etc. though.

Is this really all the information there is: http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#attr-input-multiple?

@shahata
Copy link
Contributor Author

shahata commented Sep 9, 2014

afaik the multiple attribute is only relevant for email and file inputs.
I'll update the PR tonight to expose an array in this case.
regarding delimiters, the spec says comma separated.

On Tue, Sep 9, 2014 at 1:00 PM, Narretz notifications@github.com wrote:

Honestly, I'd love to have a more robust solution for this that works with
all (text-based)-inputs similar to ngList (which exposes an array). I don't
know what the HTML spec says about delimiters etc. though.


Reply to this email directly or view it on GitHub
#8987 (comment).

@shahata
Copy link
Contributor Author

shahata commented Sep 9, 2014

@Narretz
Copy link
Contributor

Narretz commented Sep 9, 2014

Only supported for email, how odd!
Still, wouldn't it be possible to extend $$runValidators in a way that when you have multiple / ngList + the $modelValue is an array, to validate each array item? I like that better then to put the logic inside the validators.

@shahata
Copy link
Contributor Author

shahata commented Sep 9, 2014

Sounds reasonable, I'll look into it.

@shahata
Copy link
Contributor Author

shahata commented Sep 9, 2014

I've refactored this to expose an array and keep the array validation not specific to emails. I think it is hackish and ugly though. Would welcome some suggestions.

runProcessor(processAsyncValidators);

function runProcessor(fn) {
if ($attr.multiple && isArray(modelValue) && nodeName_($element) !== 'select') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this condition can be easily changed to work with ngList as well, but it is a pretty big breaking change, so I'm not sure...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the nice thing about getting this into ngList as well is obviously that we could use validators like ngPattern, maxlength, etc. which currently don't work correctly with ngList

@petebacondarwin
Copy link
Contributor

@shahata - a cool bit of works as usual. I like the idea of reusing the ngList functionality but I think if we are going to go down this road we should consider a more significant refactoring. In particular I feel uncomfortable about the if statement that has to check we are not in a select element.

How about we factor out the ngList functionality into some helper function (maybe but probably not a service). This could be mixed into the input[email] and ngList independently and possibly be made available (in the future) to allow other directives to make use of it. In the case of ngList it would be turned on all the time. In the case of input[email] it would be turned out by the presence of the multiple attribute as in this PR.

Any thoughts?

@shahata
Copy link
Contributor Author

shahata commented Sep 20, 2014

@petebacondarwin - I've refactored this a bit more, so multiple will no longer be a directive and we can remove those strange nodeName_($element) === 'select' checks. I hope this is what you meant :)

var normalized = directiveNormalize('ng-' + attrName);
ngAttributeAliasDirectives[normalized] = function() {
return {
restrict: 'A',
priority: 100,
link: function(scope, element, attr) {
// binding to multiple is not supported for select
if (propName === 'multiple' && nodeName_(element) === 'select') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to do this in order to reinstate ngMultiple for non-select elements (it is unsupported for select elements since d87fa00)

@petebacondarwin
Copy link
Contributor

@shahata - sorry I haven't got around to looking at this again yet

@jeffbcross jeffbcross force-pushed the master branch 2 times, most recently from cad9560 to f294244 Compare October 2, 2014 22:09
@jeffbcross jeffbcross force-pushed the master branch 3 times, most recently from 8292c21 to 7b9fddf Compare October 9, 2014 20:43
@jimmywarting
Copy link
Contributor

I know that angular don't support file input (coz of #1375)
This is just a speculation... and maybe of topic

@petebacondarwin if something like file input would even make use of this multiple-directive/service/helper function (in a custom directive or by angular itself in some future), I'm guessing the modelValue would be equal to input.files[0] if multiple is not present. And when it is, the modelValue would be Array.prototype.slice.call(input.files);?

Wouldn't like there to be any conflict by other element using the multiple attribute in any other ways

@stryju
Copy link

stryju commented Apr 24, 2015

bump

@Narretz Narretz self-assigned this Jun 22, 2015
@jimmywarting
Copy link
Contributor

ba da bump

@petebacondarwin petebacondarwin modified the milestones: 1.5.x - migration-facilitation, Backlog Sep 18, 2015
@Narretz
Copy link
Contributor

Narretz commented Sep 18, 2015

I am currently working on this.

@Narretz Narretz modified the milestones: 1.5.x, Backlog Apr 21, 2017
@shahata shahata closed this by deleting the head repository Jun 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.