Solved

jQuery-Validation-Engine-> validating slider position

Posted on 2014-03-04
2
381 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I do a Select All on this page? 8 36
Animated .jpg? 13 59
Error in JQuery 5 38
jQuery not working on ELSE... why? 2 22
by Julian Matz As of jQuery (http://jquery.com/) 1.4 the .live() method (http://api.jquery.com/live/) supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now