⚠ 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

Two fields (o more) in the same line for the Add/Edit form



Cèsar Martí
  • profile picture
  • Member

Posted 15 March 2012 - 15:51 PM

Hi again everybody.

What I'd like to do is this

[attachment=68:2012-03-15_163111.jpg]

To put two fields (o more) in the same line for the Add/Edit form, changing the design.

I'm trying this

[php]//**** 'boca_escenari' and 'prof_escenari' are real fields. 'escenari' it's not real ******
$crud->edit_fields('boca_escenari', 'prof_escenari', 'escenari');

$crud->change_field_type('boca_escenari', 'hidden');
$crud->change_field_type('prof_escenari', 'hidden');

$crud->callback_edit_field('escenari', array($this, 'edit_escenari_callback'));
//**** next two lines are necessari for working *******
$crud->callback_edit_field('boca_escenari', function(){return'';});
$crud->callback_edit_field('prof_escenari', function(){return'';});

function edit_escenari_callback($value = null, $primary_key = null)
{
return '<input type="text" name="boca_escenari" id="boca_escenari" class="numeric" maxlength="5" style="width:100px">'.'&nbsp; x &nbsp;'.'<input type="text" name="prof_escenari" id="prof_escenari" class="numeric" maxlength="5" style="width:100px">m';
}[/php]


At the moment, whatever I write in my custom fields is saved in the database table. The problem is, when I'm editing, I can't read the value of the table fields. Is it possible to read in a callback the value of other field (not that one)??

I think this could be usefull, cause we could re-design the forms as we wish.

Thanks.

Cèsar Martí
  • profile picture
  • Member

Posted 16 March 2012 - 12:45 PM

This could be a solution

 function edit_escenari_callback($value = null, $primary_key = null)
{
$this->db->where('facebook_id',$primary_key);
$sala = $this->db->get('sales')->row();
$boca = $sala->boca_escenari;
$prof = $sala->prof_escenari;

return '<input type="text" value="'.$boca.'" name="boca_escenari" id="boca_escenari" class="numeric" maxlength="5" style="width:100px">'.'&nbsp; x &nbsp;'.'<input type="text" value="'.$prof.'" name="prof_escenari" id="prof_escenari" class="numeric" maxlength="5" style="width:100px">m';
}


But, like this, it's necessary to access again to the Database. Isn't it possible to access to the value of the other fields of the current result without accessing again to the database?

Give me a hand, partners, please. Or tell me another idea to put two fields (o more) in the same line for the Add/Edit form.

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

Posted 20 March 2012 - 21:41 PM

[b]EDIT: [/b]I couldn't wait! I just add it :) . You can see the changes at: https://github.com/s...07de21503dacbd4 . So now with this you can have a 4th parameter with all the data of the edit.

[s]No this is the right way to do it for now in grocery CRUD. I didn't have yet the edit information at the callback. So at a future releaseI will have something like:[/s]


function edit_escenari_callback($value = null, $primary_key = null, $field_info, $edit_values)


[s]But for now this is the only way to do it.[/s]

Cèsar Martí
  • profile picture
  • Member

Posted 26 March 2012 - 15:41 PM

Nice, Johny. That's a good new. But, how can I put two fields (o more) in the same line for the Add/Edit form, changing the design, like in the image of my first post?

Thanks.

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

Posted 27 March 2012 - 21:57 PM

The only way is with the callback_add_field and callback_edit_field, but you will have to write the query from the primary key. Grocery CRUD still not support set_relation AND a callback to the same field. So just to understand you will do something like:


function edit_field_callback_1($value, $primary_key)
{
$this->db->where('id',$primary_key);
$lead = $this->db->get('leads')->row();


return "<input type='text' name='hour' value='".substr($lead->time,0,2)."'> <input type='text' name='minutes' value='".substr($lead->time,3,2)."'>";
}

and the callback_add_field is more simple:


function add_field_callback_1()
{

return "<input type='text' name='hour' > <input type='text' name='minutes'>";
}


Just ensure that you will use callback_before_insert and callback_before_update to merge the inputs.

For now this is the only solution.

Alfonso Catron
  • profile picture
  • Member

Posted 19 February 2013 - 15:43 PM

Hi everyone, this is my first post

I'm very happy with Grocerycrud, thank you for this wonderful app!

 

I know this is an old topic, but I've found that this can also be accomplished by using just CSS.

 

each field in the edit and add views is wrapped with a div, has a unique ID.

So the default style can be easily overridden adding some declarations to the theme CSS.

 

Maybe is not the best solution... but since this is a presentation issue, css might be a way?

 

Untitled-1.jpg