AmpersandJS / ampersand-select-view

Select field for ampersand-form-views
MIT License
11 stars 26 forks source link

Reports invalid despite having a value #1

Closed dhritzkiv closed 10 years ago

dhritzkiv commented 10 years ago

Passing a collection of options and choosing a default value still makes the field return false for validity.

Options: screen shot 2014-07-10 at 7 06 12 pm

In situ: screen shot 2014-07-10 at 7 02 57 pm

Asking for a value from the DOM explicitly: screen shot 2014-07-10 at 7 04 21 pm

Any idea what may be causing this? Let me know if you need more information.

dhritzkiv commented 10 years ago

After digging through the code, I believe I have found the culprit.

The relevant logic in the validation (https://github.com/AmpersandJS/ampersand-select-view/blob/master/ampersand-select-view.js#L205):

//If it's a collection, ensure it's in the collection
if (this.options.isCollection) {
    return this.options.indexOf(this.value) > -1;
}

The above code doesn't return true when the yieldModel option is set to false because the yielded string value doesn't exist in the options array.

Something like this may work better:

if (this.options.isCollection) {
    if (!this.yieldModel) {
        return !!this.options.get(this.value, this.idAttribute);
    }
    return this.options.indexOf(this.value) > -1;
}

Thoughts?

latentflip commented 10 years ago

Hi @dhritzkiv, sorry about that! It would seem I fixed this, but forgot to actually push & publish it!

Now published as 1.0.2 and fixed here: https://github.com/AmpersandJS/ampersand-select-view/commit/4e4c5a582a3a57096e5afeb7f123b691d2d0371b

dhritzkiv commented 10 years ago

Perfect. Thanks!

On Jul 12, 2014, at 13:03, Philip Roberts notifications@github.com wrote:

Hi @dhritzkiv, sorry about that! It would seem I fixed this, but forgot to actually push & publish it!

Now published as 1.0.2 and fixed here: 4e4c5a5

— Reply to this email directly or view it on GitHub.