⚠ 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

Field type "invisible" not possible when field have relation



jonathanw

jonathanw
  • profile picture
  • Member

Posted 26 March 2014 - 14:55 PM

Hi,

 

I've have a little bit of an issue.

In one of the controllers ("pages") of my application, I want a logged in user to add an entry.

 

On the index of the controller, ie, the list of all posts, the users firstname and lastname should be seen.

Easy-peasy, right;

$crud->set_relation('user_id','users','{first_name} {last_name}');

But - I want to disable the input field on add and edit, because I want the user_id to be set automaticly (from a session variable).

This doesn't work, so I googled the problem and found a post somewhere on this forum saying that a field cannot be invisible (or for that matter disabled) when it has a relation.

 

I get the point that when you use a relation in the list, the same relation should be used to get a dropdown of possible values. But in this case, it's not needed. Or really, it's not even smart to have it, since each post should have the correct creator.

 

Is there a way to fix this?

 

I've done this to get it working:

public function _callback_set_username($value,$row) {
        return "<input id='field-user_id' name='user_id' type='text' value='".$_SESSION['first_name']." ".$_SESSION['last_name']."' readonly='readonly' disabled='disabled' />";
    }

$crud->callback_field('user_id',array($this,'_callback_set_username'));

And a in another callback, used on callback_before_insert/update, the sessions user_id is set to the post data user_id.

It works, but it seems like a bit of extra coding for no reason.

 

Regards

Jonathan


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 26 March 2014 - 19:44 PM

well yes this has been out for quite some times..

the way you have done is fine..

the other way round is ... dont set the relation if in case you want to hide it...

this can be performed in with the state of crud.. like if listing - set relation with it.. if not. ... make it hidden

 

Happy GCing :)


jonathanw

jonathanw
  • profile picture
  • Member

Posted 27 March 2014 - 12:26 PM

I was looking for something in between - keeping the relation but hiding it from editing...

We'll, I guess I'll keep to my solution as of now.


Sergio Rodríguez Segura

Sergio Rodríguez Segura
  • profile picture
  • Member

Posted 07 April 2014 - 22:20 PM

Se puede hacer con javascript, solo ocultas el div correspondiente a tu campo

 

$( "#field1" ).hide();