seiyria / bootstrap-slider

A slider control for Bootstrap 3 & 4.
http://seiyria.github.io/bootstrap-slider/
Other
2.99k stars 1.14k forks source link

What about validation? #741

Open stephanrauh opened 7 years ago

stephanrauh commented 7 years ago

Currently, we're including your slider as a BootsFaces widget (see http://www3.bootsfaces.net/Showcase/bootstrap/Slider2.jsf). Among other things, this means we need to be able to report error messages. I agree this makes hardly ever sense, but if someone defines a validation constraint we'd like to indicate that the slider has an illegal value. Standard Bootstrap input widgets use this approach: http://getbootstrap.com/css/#forms-control-validation.

Is there anything similar for the bootstrap-slider?

seiyria commented 7 years ago

This is not a thing we support. Your best bet at this time would be to either:

seiyria commented 7 years ago

That said, I think this is a feature worth accepting a PR for, so if we were to accept one, I would like it to color the border of the slider in the same style as bootstrap inputs.

stephanrauh commented 7 years ago

Sure, we can talk about submitting a PR. But before that, I'd like to get an idea what's a clever approach. I guess coloring the border according to the Bootstrap styles works well enough in most cases.

Following the recommended HTML code for regular input fields, we would mark the "offending" (for want of a better word) slider like so:

<div class="form-group has-error">
  <label class="control-label" for="age">Please enter your age (18-65)</label>
  <input id="age" data-slider-id='ex1Slider' type="text" data-slider-min="0" 
    data-slider-max="99" data-slider-step="1" data-slider-value="14"/>
</div>l

Does this match your ideas?

seiyria commented 7 years ago

I think that would be fine, so long as the generated HTML still includes the slider class (so you're targetting .has-error .slider in your CSS). Makes sense to me.

stephanrauh commented 7 years ago

OK! I think we'll test the idea first in BootsFaces. If the idea works out, I'll prepare a pull request for you.

(Isn't open source great? Being able to improve things actively? That's something that's much more difficult with commercial software!)

seiyria commented 7 years ago

Sounds good, feel free to pass it along when you've got a working idea (just remember to follow all the PR guidelines!).

Open source is pretty nice for that, yeah. It's why we do what we do :D