Raphael Schmid
2006-Mar-22 20:32 UTC
[Rails] Setting empty fields with in_place_editor_field
Hi all! Playing around with in_place_editor_field, I found that when you set a field to be empty, you can''t edit it at all anymore after that. Am I doing something wrong or is this the way it is intended to be? If so, is there any way around that behaviour? Is it just styling? Best regards, Raphael -- Posted via http://www.ruby-forum.com/.
Raphael Schmid
2006-Mar-24 13:34 UTC
[Rails] Re: Setting empty fields with in_place_editor_field
Does really nobody use in_place_editor_field like that, for setting a previously empty field to some value? -- Posted via http://www.ruby-forum.com/.
Eric Wagoner
2006-Mar-24 14:00 UTC
[Rails] Re: Setting empty fields with in_place_editor_field
On 3/24/06, Raphael Schmid <raphael@schwarzschmid.de> wrote:> Does really nobody use in_place_editor_field like that, for setting a > previously empty field to some value?Whereever I use an in_place_editor, I make sure that nil values cannot be saved in the controller. Instead of nil, I save "Unknown" or something similar. -eric
Raphael Schmid
2006-Mar-24 23:37 UTC
[Rails] Re: Re: Setting empty fields with in_place_editor_field
That''s a simple yet wonderful idea -- I''ll go with a dash. Thanks a lot Eric! -- Posted via http://www.ruby-forum.com/.
Curtis Hatter
2006-Mar-25 02:25 UTC
[Rails] Re: Setting empty fields with in_place_editor_field
Raphael Schmid wrote:>Does really nobody use in_place_editor_field like that, for setting a >previously empty field to some value? > > >Here''s a way I''ve been experimenting with: <% for column in Books.content_columns %> <p> <span id="<%= column.name -%>"><b><%= column.human_name %>:</b></span> <%= in_place_editor_field :books, column.name, {}, {:external_control => column.name } -%> </p> <% end %> That makes both the value and label clickable. The only issue is that editing causes the label to disappear. Can anyone say if this is the proper behavior? The docs say ":external_control:: The id of an external control used to enter edit mode." and to me that doesn''t give an indication that it should disappear. Regardless, it does allow for editing empty fields. Curtis
Curtis Hatter
2006-Mar-25 02:31 UTC
[Rails] Re: Setting empty fields with in_place_editor_field
Curtis Hatter wrote:> Raphael Schmid wrote: > >> Does really nobody use in_place_editor_field like that, for setting a >> previously empty field to some value? >> >> >> > Here''s a way I''ve been experimenting with: > > <% for column in Books.content_columns %> > <p> > <span id="<%= column.name -%>"><b><%= column.human_name %>:</b></span> > <%= in_place_editor_field :books, column.name, {}, {:external_control > => column.name } -%> > </p> > <% end %> > > That makes both the value and label clickable. > > The only issue is that editing causes the label to disappear. Can > anyone say if this is the proper behavior? The docs say > ":external_control:: The id of an external control used to enter edit > mode." and to me that doesn''t give an indication that it should > disappear. > > Regardless, it does allow for editing empty fields. > > Curtis > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Here''s a way to fix the in_place_editor so that it doesn''t hide the label. in ''public/javascripts/controls.js'' comment out lines 513-515 (this going off most recent edge rails). The lines are: if (this.options.externalControl) { Element.hide(this.options.externalControl); } Hope that gives the effect you are looking for, Curtis
This may be of help. I''ve created a helper method that overcomes the problem in my applications: [code] #Variation of in_place_editor_field, which add a plus sign in empty fields so there is something to select #Usage: item = object that field is a property of # symbol = name of object represented as a symbol # field = the name of the property/field to have edit function (symbol) # user_can_edit = boolean. in_place_editor only available if true def in_place_editor_field_with_empty(item, symbol, field, user_can_edit) if user_can_edit output_text = String.new eef_id = ''eef_'' + field.to_s + item.id.to_s if not item.send(field) or item.send(field).length < 1 output_text += ''<span class="empty_edit_field" id="'' + eef_id + ''">+</span>'' end output_text += in_place_editor_field symbol, field, {}, {:external_control => eef_id } else item.send(field) end end [/code] It checks to see if the propert is empty and adds a plus sign instead of a blank entry. Clicking on the plus sign opens the in place editor. You can use the empty_edit_field class in CSS to control the appearance of the plus sign. I think you should be able to replace symbol with a function of item, but I haven''t worked out the right one yet. I use it like this in a rhtml template: <td><%= in_place_editor_field_with_empty(@stock, :stock, :purchase_order, user_logged_on?) -%></td> where @stock is an item of stock :stock a symbol for that item :purchase_order is the name of the property being edited : @stock.purchase_order :user_logged_on? is another helper function that checks the users log on status. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Nichols wrote:> if not item.send(field) or item.send(field).length < 1Small bug fix. This causes an error if propert isn''t a string, so: if not item.send(field) or item.send(field).to_s.length < 1 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
here''s a great extension that someone else wrote. I use it in my apps now. it should probably be part of the core: http://www.akuaku.org/archives/2006/08/in_place_editor_1.shtml On 12/20/06, Rob Nichols <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Rob Nichols wrote: > > if not item.send(field) or item.send(field).length < 1 > > Small bug fix. This causes an error if propert isn''t a string, so: > > if not item.send(field) or item.send(field).to_s.length < 1 > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Mike Weber Web Developer UW-Eau Claire --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I spent way too long trying to solve this problem. I was not having any luck implementing any helpers or extensions in 2.3.2, and did not want to set my database fields to "No data" or whatever to populate the blank fields. I therefore went with the old standby, dealing with the CSS through javascript. Slightly hacky, but it works across browsers: <body onload="fixElements();"> And the javascript: function classes(cn, mom) { //from rnd_me at codingforums.com if(!mom){mom=document;} if(mom.getElementsByClassName){ return mom.getElementsByClassName(cn); } var rx = new RegExp("(?:^|\\s)" + cn+ "(?:$|\\s)"); var allT = mom.getElementsByTagName("*"), allCN = [], ac="", i = 0, a; while (a = allT[i=i+1]) { ac=a.className; if ( ac && ac.indexOf(cn) !==-1) { if(ac===cn){ allCN[allCN.length] = a; continue; } rx.test(ac) ? (allCN[allCN.length] = a) : 0; } } return allCN; } function fixElements() { var emptyInlineEdits = classes("in_place_editor_field"); for (var i=0; i < emptyInlineEdits.length; i++) { if (emptyInlineEdits[i].innerHTML=='''') { emptyInlineEdits[i].innerHTML=''_''; } } } I hope this can save someone some time! -- Posted via http://www.ruby-forum.com/.