Solved

jQuery-Validation-Engine-> validating slider position

Posted on 2014-03-04
2
390 Views
Last Modified: 2014-03-04
I cannot make a slider validate using this plugin, Can anyone help out here?

I've tried putting the validation on the hidden field and on the slider div but it won't  validate in either case.

HTML:
    As an anti-spam measure, please drag the slider below to the right until the 
    color changes.<span class="required" id="slider_required">(required)</span>
    <input type="hidden" name="CSlider" id="CSlider" value="0" />
    <br />
    <div id="slider" class="validate[required,funcCall[sliderCheck]]"></div>

Open in new window

Javacript:
    $(document).ready(function () {
        $("#slider").slider({
            value: 0,
            min: 0,
            max: 1,
            step: 1,
            slide: function (event, ui) {
                $("#CSlider").val(ui.value);
                // Don't need the color change for the thumb
                if (ui.value == 1) {
                    $("#slider").children("a").css("background", "#48B");
                    $("#slider").css("background", "#F7F6F1");
                } else {
                    $("#slider").children("a").css("background", "#F7F6F1");
                    $("#slider").css("background", "#F7F6F1");
                }
            }
        });
    });

    function sliderCheck(field, rules, i, options) {
        if(field.val() != 1) {
            return options.allrules.validate2field.alertText;
        }
    }

Open in new window


CSS:
    #slider {
        display:inline-block;
        background-position:left top;
        background-repeat:repeat-x;
        border:1px solid #ccc;
        float:left;
        margin-left: 25px;
        padding:0;
        width:120px;
        }    

Open in new window

0
Comment
Question by:EddieShipman
  • 2
2 Comments
 
LVL 26

Accepted Solution

by:
EddieShipman earned 0 total points
ID: 39903819
Ok, finally figured it out. Posting for others to see.

After the slider is initialized, I need to bind the anchor's blur to my validation function:
$("#slider").children("a").bind("blur", sliderCheck);

Open in new window

Then I show the Prompt on the slider div:
function sliderCheck() {
    if($("#CommentSlider").val() != 1) {
        $('#slider').validationEngine('showPrompt', 'Please move the slider to the right before submitting the form');
    }
}

Open in new window

0
 
LVL 26

Author Closing Comment

by:EddieShipman
ID: 39903823
For others to see.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question