ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Safecracker with JS validation...

September 05, 2012 9:09pm

Subscribe [2]
  • #1 / Sep 05, 2012 9:09pm

    shorn

    79 posts

    Hi all,

    Just a quickie that I am hoping someone can point me in the right direction. My site uses Twitter Bootstrap CSS for the make up of alot of elements, including form fields.

    I found this JS Validation specifically for Bootstrap, so i have set about implementing it. I tried it out on my contact form (using native contact form code), and it works perfectly, however when I added it to my safecracker form, its not working.

    What should I be looking at to start narrowing down whats wrong? and is there anything that differ between safecracker and the contact form, that would cause the issue?

    thanks!

  • #2 / Sep 07, 2012 2:10pm

    Kevin Smith

    4784 posts

    Hi shorn,

    I know SafeCracker has it’s own form validation and JS libraries, so it’s possible there’s some conflict there. I doubt it there’s a conflict with the validation, but that’s a first place to look.

    When you say it’s not working, could you describe a bit more what that looks like?

    Have you checked your browser’s JavaScript console to see if there are any JS errors involved? Since SafeCracker loads its own jQuery at the bottom of the page, perhaps you’re trying to load this validation plugin before jQuery is loaded. Mind sharing your full template here? I’d love to help you debug it.

  • #3 / Sep 09, 2012 1:11pm

    shorn

    79 posts

    Hi, thanks for responding, sorry for the delay in getting back to you, I hope to be looking at this again very shortly, (next couple of days) so will post up with some code! Thanks!

  • #4 / Sep 10, 2012 4:40pm

    Shane Eckert

    7174 posts

    Hey shorn,

    Sounds good! We will be on the lookout for your update.

    Cheers,

  • #5 / Sep 10, 2012 5:42pm

    shorn

    79 posts

    Ok, lets see if we can get somewhere!

    First off, it works perfectly in the contact form that I have. Here is the contact form. (I have condensed it slightly.) As you can see the JS validation requires the “required” parameter in the field. If the user tries to submit the form without filling it in, it will turn red, and display an error message in the “help-block” element. (As per error class Bootstrap styling.)

    {exp:email:contact_form charset="utf-8" recipients="[email protected]" redirect="none" return="http://myurl | Return to Home Page"}
    <div class="control-group">
    <label><strong>Your email address:</strong></label>
                <div class="controls">
                 <input id="from" class="text" type="email" name="from" value="{member_email}" required/>
                 /p>
                </div>
               </div>
           
           <div class="control-group">
                <label><strong>Your name:</strong></label>
                <div class="controls">
                 <input class="span6" size="25" type="text" name="name" required/>
                 /p>
            </div>
           </div>
    <button type="submit" class="btn btn-success" name="submit"><i class="icon-envelope icon-white"></i> Send message</button>
       {/exp:email:contact_form}

    However, this is not happening in Safecracker. In both forms the jqBootstrapValidation.js is loaded in the HEAD.

    <link media="all" rel="stylesheet" type="text/css" href="/-/css/all.css" />
     <link media="all" rel="stylesheet" type="text/css" href="/-/css/basic-jquery-slider.css" />
     [removed][removed]
     [removed][removed]
     [removed][removed]
     [removed][removed]
     [removed][removed]
     [removed][removed]

    and at the start of the BODY…

    [removed]
      $(function () { $("input,select,textarea").not("[type=submit]").jqBootstrapValidation(); } );
    [removed]

    Now I tried adding the “required” to the first field of my safecracker form, (the code below just shows the form tags and first field)

    {exp:safecracker id="addwalk" channel="walks" return="forms/thanks" status="Pending" logged_out_member_id="1" dynamic_title="[walk_name]" }
         <fieldset>
         <div class="control-group">
         <label for="walk_name"><strong>1. Walk Name</strong></label>
         <div class="controls">
         <input type="text" class="span6" name="walk_name" id="walk_name" value="{walk_name}" required/>
         /p>
          </div>
         </div>
    <button type="submit" class="btn btn-success" name="submit"><i class="icon-ok icon-white"></i> Submit this walk</button>
         </fieldset>
        {/exp:safecracker}

    This field displays fine, and when you click into it to start typing, it turns red (as it should) but when you start typing it returns to a normal text field, whereby it should be styled green.
    Looking at the javascript console (chrome) for the safecracker form, I have the following error message…

    Uncaught TypeError: Object [object Object] has no method ‘jqBootstrapValidation’

    I hope this helps, I’m not quite sure where to go. Still new to EE, but learning all the time. Happy to follow any instructions or add anything else you need to know, but need some direction to help solve this one!

    Thanks

  • #6 / Sep 10, 2012 7:43pm

    shorn

    79 posts

    Well I think I might have possibly answered my own question! by including, include_jquery=“no”  parameter into teh safecracker tag, it appears to be working. Will continue to test and report back!

  • #7 / Sep 11, 2012 2:08pm

    Dan Decker

    7338 posts

    Hi shorn,

    I, personally, haven’t seen you around in a while! Nice to have you back.

    Look forward to hearing of your progress.

    ~

  • #8 / Sep 11, 2012 2:12pm

    shorn

    79 posts

    Yep, I’ve kinda let the site take shape before starting on any new development. Now just making everything work a bit better! (Or at least trying to!)
    This seems fine now, just need to work out how to get it playing nice with dropdowns, but I think this may be one I can work out. Will be posting up shortly a few questions about “searching” so expect a few more from me! 😊

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases