anjlab / bootstrap-rails

Twitter Bootstrap CSS (with Sass flavour) and JS toolkits for Rails 3 projects
https://github.com/anjlab/bootstrap-rails
729 stars 96 forks source link

disable input fields in form on the basis of devices. #71

Closed aman199002 closed 11 years ago

aman199002 commented 11 years ago

I am using rc bootstrap in my rails application. I want to see a form in different style according to devices.For this i am using this code:

=simple_form_for @ticket do |f|
  div.row
    .hidden-sm
      .col-9.col-sm-9.col-lg-9
        = f.text_field :price
    .hidden-lg
      .col-12.col-sm-12.col-lg-12
        = f.text_field :price,  :style => "height:0.8cm;width:0.8cm;"
  = f.submit

But when i edit my record via this form, i receive 2 params[:ticket][:price] records, the input field is only hidden according to device but its value is passed. Is there any way to disable the input-fields according to devices.

yury commented 11 years ago

you need to disable inputs (html attribute disable='disable'), not just hide them.

Don't know how to do that without JS

yury commented 11 years ago

Closing this issue. This is not related to this gem

aman199002 commented 11 years ago

This issue is not directly related to gem but with rc bootstrap.I have solved the issue using js by disabling all the inputs for hidden block that are being used for other devices.

=simple_form_for @ticket do |f|
  div.row
    .hidden-sm.large_screen
      .col-9.col-sm-9.col-lg-9
        = f.text_field :price
    .hidden-lg.mobile_screen
      .col-12.col-sm-12.col-lg-12
        = f.text_field :price,  :style => "height:0.8cm;width:0.8cm;"
  = f.submit

The div blocks specified for other devices will remain hidden if page is loaded on a specific device. And we want to skip those elements. So, disabled those if particular div block is hidden, so that multiple parameters will not be passed for same attribute while submitting the form.

In js file

 $('div.mobile_screen :input').attr('disabled', true) if $('div.mobile_screen').is(":hidden")
 $('div.large_screen :input').attr('disabled', true) if $('div.large_screen').is(":hidden")

Issue Resolved.