Skip to content

Instantly share code, notes, and snippets.

@esbanarango
Last active May 8, 2018 18:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save esbanarango/6629748 to your computer and use it in GitHub Desktop.
Save esbanarango/6629748 to your computer and use it in GitHub Desktop.
HTML <input> required attribute and Rails form with remote true.

<input> with attribute required

This attribute specifies that the user must fill in a value before submitting a form. It cannot be used when the type attribute is hidden, image, or a button type (submit, reset, or button). The :optional and :required CSS pseudo-classes will be applied to the field as appropriate.

How to show a spinner only when the required validations pass? (Without using any validation plugin, only the required attribute).

Form with a required input

= form_for @person, remote: true do |f|
  = f.text_field, :first_name, required: true
  = f.submit "Create"

Solution

  $(document).on("ajax:beforeSend", "form[data-remote]", function(e){
    /* spinner show logic */
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment