Solved

jQuery-Validation-Engine-> validating slider position

Posted on 2014-03-04
2
375 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
Comment Utility
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
Comment Utility
For others to see.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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 how to dynamically set the form action using jQuery.
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)

743 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

17 Experts available now in Live!

Get 1:1 Help Now