Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7826145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:16:43+00:00 2026-06-02T09:16:43+00:00

I have this form in HAML: = form_for([:mobile,@disclosure], :html => {:id => add_validation_to_ajax_form, :remote

  • 0

I have this form in HAML:

= form_for([:mobile,@disclosure], :html => {:id => "add_validation_to_ajax_form", :remote => true}) do |f|

but the add_validation_to_ajax_form function has a a parameter like this:

function add_validation_to_ajax_form(form_selector){
    alert ("hello :)");
    add_custom_validation_methods();
    $(form_selector).submit(function(event) {
      force_ckeditor_to_update();
    }).validate({meta:"validate",onkeyup:false,validClass:"ok-input",
          errorPlacement: function(error, element) {

          }
      });
}

And I am new to the HAML syntax of how it is supposed to call the JavaScript function. Right now when the form is submitted, this function is not displaying the hello popup. Any idea why it isn’t working?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:16:44+00:00Added an answer on June 2, 2026 at 9:16 am

    That’s because you’re not calling the function anywhere. If you want it to execute you have to call it.

    Try adding this to your application.js file.

    $(function() {
      add_validation_to_ajax_form('form#add_validation_to_ajax_form');
    });
    

    That will call your function. However, I think the function you WANT to have looks more like this:

    $(function() {
      $('form#add_validation_to_ajax_form').submit( function() {
        alert ("hello :)");
        add_custom_validation_methods();
        force_ckeditor_to_update();
        $(this).validate({
          meta:"validate",
          onkeyup:false,
          validClass:"ok-input",
          errorPlacement: function(error, element) {}
        });
      });
    });
    

    The $(function(){ ... }); call in jQuery means: do this when the page is finished loading.

    The $(selector).submit( function(){...}); function means, find the selector on the page, and attach a submit event handler to it, so that when the form is submitted the stuff in this function happens.

    If you must embed something like this in HAML you can by indenting behind :javascript, like so:

    :javascript
      $(function(){ alert('The page is loaded!') });
    

    HAML really has nothing to do with whether or not your function is called though. HAML creates HTML. All HAML needs to do is include the javascript files somewhere, (javascript_include_tag). In Rails > 3.1.x the best practice is for your layout to include your application.js file, and for the rest of your javascripts to be loaded through that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this form for inputting the birthday in html. But I only have
I have this view: new.html.haml %h1 New account - form_for @user do |f| =
I have this in one of my haml views: -form_for :news_item_comment, :url=>{:id => comment.id,
I have this form submit code: Event.observe(window, 'load', init, false); function init() { Event.observe('addressForm',
Have converted devise new session from erb to Haml but doens't work, this is
I have this form with inputs with the same name but similar (incremental) ids.
I have this form: <%= form_for(@post) do |f| %> <%=f.collection_select :post_id, Board.where(:user_id => current_user.id),
Rails 2.3.11. I have a search form like this... - form_for(@search) do |form| #
I have a quite average form in Rails, trough blog_kit <% form_for(@blog_post, :html =>
I have a form, that looks like this (sorry for Haml and the german

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.