Omar
Omar

Reputation: 861

How to add a disabled submit button in rails

I have a submit button in a form in ruby

f.submit btn_text, class: "btn btn-one mgt12 mgb12", id: "btn_id"

I want to make this button disabled by ruby without using any javascript

Upvotes: 11

Views: 13823

Answers (2)

H12
H12

Reputation: 31

To expand upon Arup's answer, adding disabled: true as an argument in your f.submit would generate the following HTML:

<input class="btn btn-one mgt12 mgb12" disabled="disabled" id="btn_id" name="commit" type="submit" value="#{btn_text}">

Furthermore, if you want to select the disabled input for custom styling, you can do the following:

input[disabled="disabled"] {
    cursor: not-allowed;
}

Upvotes: 2

Arup Rakshit
Arup Rakshit

Reputation: 118261

Add disabled: true option.

f.submit btn_text,
  class: "btn btn-one mgt12 mgb12",
  id: "btn_id",
  disabled: true

Upvotes: 21

Related Questions