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

  • SEARCH
  • Home
  • 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 5850339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:07:37+00:00 2026-05-22T13:07:37+00:00

i am using the rails 3 UJS for my forms. In one of the

  • 0

i am using the rails 3 UJS for my forms.

In one of the fields, i have the default value as “ABC”.

If the user did not change the field, I do not want this value to be submitted.

1) It is an optional field, so i do not want to prevent the form from submitting

2) I could hijack the “:before” action, but that seems hackish to me

This seems like a common use case – what is the most elegant way of doing this?

  • 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-05-22T13:07:37+00:00Added an answer on May 22, 2026 at 1:07 pm

    If you only want to support HTML5-aware browsers, you can use the placeholder attribute of the <input> tag instead of setting a value you don’t want to submit.

    <input type="text" placeholder="ABC" />
    

    Bear in mind that IE9 does not support this attribute (source).

    If you’d rather not, you could use the form’s submit event to clear the form field if it hasn’t been changed.

    $("#my-form").submit(function(event) {
        var input = $("#my-input-box");
        if (input.val() === "ABC") {
            input.val("");
        }
    });
    

    You may find that your users sometimes want to type “ABC” into the box. You can solve this by setting a flag when the contents are changed and checking whether the flag is set in the above code instead of comparing the current value to the default.

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

Sidebar

Related Questions

Using Rails 3.1.3 with Ruby 1.9.3p0. I've discovered that by default, Rails does not
I'm doing some Rails stuff with AJAX (not using UJS, but rather rolling my
I am using Rails 3, Jquery-UJS and Jquery. I have a working setup of
Using Ruby 1.8.7-p358, Rails 3.0.12, gem responder, gem simple-form; jquery_ujs.js I have a form
Using Rails 3.2.2 and ruby 1.9.2 and I am not able to serve assets
Using Rails 3.2. I have an individual Shop post, and each shop has reviews.
Using Rails 3.1.3 and Ruby 1.9.3. I want to give the user a list
Using Rails ActiveRecord, am wanting to calculate the time between two datetime fields within
I have a new application starting that's using Rails 2.3.8 for stability concerns and
I'm using Rails UJS to load partials into a container depending on the link

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.