Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jQuery-Validation-Engine-> validating slider position

Posted on 2014-03-04
2
Medium Priority
?
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

718 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