Giter Club home page Giter Club logo

Comments (8)

miguelcobain avatar miguelcobain commented on July 19, 2024

What is the expected behaviour? Adding a required attribute?

from ember-cli-selectize.

knownasilya avatar knownasilya commented on July 19, 2024
{{ember-selectize required=true}}

Would pass required to the underlying <select> which would prevent a form submit.

from ember-cli-selectize.

miguelcobain avatar miguelcobain commented on July 19, 2024

Fixed in 1871455
Please update to latest version.
Let me know if you have any problems. Thanks.

from ember-cli-selectize.

knownasilya avatar knownasilya commented on July 19, 2024

Works partially, it doesn't submit the form, but it also doesn't show a tooltip saying that this field is required..

from ember-cli-selectize.

miguelcobain avatar miguelcobain commented on July 19, 2024

but it also doesn't show a tooltip saying that this field is required..

Is this something related with ember-selectize or Selectize itself?

Here's a jsbin with selectize only and required attribute: http://jsbin.com/yoqohadewo/1/edit?html,js,console,output

Nothing really happens. Feel free to change the JSBin if you know how to replicate the expected behavior.
Isn't this a question of styles/theme?

from ember-cli-selectize.

knownasilya avatar knownasilya commented on July 19, 2024

http://jsbin.com/lisucupaka/1/

Hit "Submit" without selecting an option.

from ember-cli-selectize.

miguelcobain avatar miguelcobain commented on July 19, 2024

Ok, gotcha.

The thing is that Selectize is a wrapper around a select element. If you inspect the DOM, you can see the underlying select has the style display:none. What you see with selectize is actually a div that "proxies" or "reflects" to that select element.
That tooltip you see in your JSBin is part of the native select browser features. It may even be different in some browsers, for example.

Selectize's support for required was done in this PR selectize/selectize.js#136.

Basically:

  • If the underlying select has required attribute, selectize adds the required class to the wrapper
  • If a submit is attempted while no value was chosen, selectize adds an invalid class to the wrapper (listens to the invalid event)
  • The styling is up to the developer/theme to do

Check this JSBin: http://jsbin.com/cewesuviqa/1/edit?html,js,console,output
Try to submit and then inspect the DOM. Both required and invalid classes are added.

Ember-selectize focuses on bringing the features of selectize to Ember. This is clearly out of this project scope. But even for Selectize, I don't see a way to do what you need without styling this "invalid" state yourself.

Bootstrap, for example, has styles for these invalid states on all its form controls.
Hope I was clear enough.

from ember-cli-selectize.

jorr avatar jorr commented on July 19, 2024

Even after updating to the latest version, I am still having problems with this. Why not remove the "required" attribute on the original element? It is still being targeted for focusing and failing if empty on submit, causing browser errors in the console.

from ember-cli-selectize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.