Two fields (o more) in the same line for the Add/Edit form
- Single Page
Posted 15 March 2012 - 15:51 PM
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">'.' x '.'<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.
Posted 16 March 2012 - 12:45 PM
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">'.' x '.'<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.
Posted 20 March 2012 - 21:41 PM
[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]
Posted 26 March 2012 - 15:41 PM
Thanks.
Posted 27 March 2012 - 21:57 PM
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.
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?