(this is my first post on the ruby forum. If this is not the right place for this type of question please let me know). Ajax question I have a checkbox that toggles the visibility of another element (a text field) with the code: --- <p><label for="checkbox">Appear!</label> <%= check_box :object_name, :method, :onClick => "Element.toggle(''text_field_to_toggle'')" %> <%= text_field :object_name, :method, :disabled => ''true'' %> </p> --- the text field is: --- <%= text_field :object_name, :text_field_to_toggle %></p> -- It works well, the only problem is that it HIDES the text field which is initialy visible. How can i make the the initial state of an element hidden so it can be toggled to visible. Is there a parameter on the text box element that can set the initial state hidden or it should be implemented in javascript? Thank you in advance. -- Posted via http://www.ruby-forum.com/.
Frantz Gauthier
2006-Jul-18 17:10 UTC
[Rails] Re: Turn element hidden by default (ajax question)
John Brown <fanmih@...> writes:> > (this is my first post on the ruby forum. If this is not the right place > for this type of question please let me know). > > Ajax question > I have a checkbox that toggles the visibility of another element (a text > field) with the code: > --- > <p><label for="checkbox">Appear!</label> > <%= check_box :object_name, :method, :onClick => > "Element.toggle(''text_field_to_toggle'')" %> > <%= text_field :object_name, :method, :disabled => ''true'' %> > </p> > --- > the text field is: > --- > <%= text_field :object_name, :text_field_to_toggle %></p> > -- > It works well, the only problem is that it HIDES the text field which is > initialy visible. How can i make the the initial state of an element > hidden so it can be toggled to visible. Is there a parameter on the text > box element that can set the initial state hidden or it should be > implemented in javascript? > Thank you in advance. >I think that you just have to write your tag like this : <%= text_field :object_name, :text_field_to_toggle , :style => "display: none" %> The rule "display: none" must be inline and not in a separate css file if you want Element.toggle working properly. -- Frantz Gauthier
Ross Riley
2006-Jul-18 17:52 UTC
[Rails] Re: Turn element hidden by default (ajax question)
Just a general piece of advice, using css to set the visibility to none is fine but bear in mind that if someone hasn''t got javascript enabled that element will never appear. I''ve always found that using javascript to hide elements is better since that way you don''t obscure anything from people who have it turned off. A function like the following will hide everything with a class name of ''hideme''. Event.observe(window, ''load'', function() { allNodes = document.getElementsByClassName("hideme"); for(i = 0; i < allNodes.length; i++) { allNodes[i].style.display="none"; } } ); If you don''t need to hide a whole class of items then target by ID for performance reasons. Ross On 7/18/06, Frantz Gauthier <frantz.gauthier@gmail.com> wrote:> John Brown <fanmih@...> writes: > > > > > (this is my first post on the ruby forum. If this is not the right place > > for this type of question please let me know). > > > > Ajax question > > I have a checkbox that toggles the visibility of another element (a text > > field) with the code: > > --- > > <p><label for="checkbox">Appear!</label> > > <%= check_box :object_name, :method, :onClick => > > "Element.toggle(''text_field_to_toggle'')" %> > > <%= text_field :object_name, :method, :disabled => ''true'' %> > > </p> > > --- > > the text field is: > > --- > > <%= text_field :object_name, :text_field_to_toggle %></p> > > -- > > It works well, the only problem is that it HIDES the text field which is > > initialy visible. How can i make the the initial state of an element > > hidden so it can be toggled to visible. Is there a parameter on the text > > box element that can set the initial state hidden or it should be > > implemented in javascript? > > Thank you in advance. > > > > I think that you just have to write your tag like this : > <%= text_field :object_name, :text_field_to_toggle , :style => "display: none" %> > > The rule "display: none" must be inline and not in a separate css file if you > want Element.toggle working properly. > > -- > Frantz Gauthier > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ross Riley riley.ross@gmail.com
Reasonably Related Threads
- ActionView::Helpers::FormHelper instance methods should take an object reference rather than an object_name.
- Creating a new virtual field
- How do i switch off error wrapping for a specific field?
- Overwrite form helper methods and call old ones in new ones?
- Popup Calendar and DateBoxEngine and Change Made ...