⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

unset_fields after fields



lherlaar
  • profile picture
  • Member

Posted 16 May 2012 - 15:43 PM

Hi,

I think I just stumbled upon a small bug:

According to some conditions, I sometimes want to unset some fields that I set before. I use grocery_crud->unset_fields for this. However, if I first set the field using grocery_crud->fields, unsetting it has no effect anymore. So:

...->grocery_crud->fields('a', 'b', 'c');

followed by

...->grocery_crud->unset_fields('b');

will still display 'b' in the add/edit screen.

For unset_columns / columns behavior is working as expected (so you can unset a column after first setting it).

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 16 May 2012 - 16:57 PM

Actually this is the expected behaviour . The unset_field is used only for the automatically created fields. If you have the [font=helvetica, arial, sans-serif][color=#282828]fields('a', 'b', 'c'); this means that you already chose your fields. [/color][/font]

[font=helvetica, arial, sans-serif][color=#282828]The purpose of the unset_fields is used for example if you have 15 fields at your database and you just want to unset two fields. [/color][/font]

[font=helvetica, arial, sans-serif][color=#282828]So before the creation of unset_field (before 1.2) you would write:[/color][/font]

[font=helvetica, arial, sans-serif][color=#282828]

$crud->fields('a','b','c','d',...'w','s');
[/color][/font]

[color=#282828][font=helvetica, arial, sans-serif]but now you can simply write: [/font][/color]

[font=helvetica, arial, sans-serif][color=#282828]

$crud->unset_fields('m','l');
[/color][/font]

[color=#282828][font=helvetica, arial, sans-serif]and that's it[/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]Perhaps at a future release I will change it to be like unset_columns (so you can set and unset fields), but we can live without it [/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#282828][font=helvetica, arial, sans-serif] :)[/font][/color]

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 16 May 2012 - 18:17 PM

I also track it so to remember to do it: https://github.com/scoumbourdis/grocery-crud/issues/36

Thanks to mention it.

lherlaar
  • profile picture
  • Member

Posted 16 May 2012 - 20:38 PM

Thanks! I understand that first setting the fields and then unsetting them looks a bit involved, but let me explain: the reason for this is actually to have them displayed in a certain order, instead of the order they have in the database. So as a default I first set all the fields in the preferred display order and then I unset the ones I don't want, according to the circumstances.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 16 May 2012 - 20:56 PM

It make sense. I will try to fix that as for the next version but not promising anything.

For now a let's name it "work around" for your situation is this:


$this->fields('test1','test2','test3'); //'test4','test5','test6'


what do you think?