⚠ In case you've missed it we are migrating 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 forum is read-only and soon will be archived. ⚠

Field type "invisible" not possible when field have relation

field_type relation set_relation invisible disabled

  • Please log in to reply
3 replies to this topic

#1 jonathanw



  • Members
  • PipPip
  • 12 posts

Posted 26 March 2014 - 02:55 PM



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' />";


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.




#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts

Posted 26 March 2014 - 07: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 :)

#3 jonathanw



  • Members
  • PipPip
  • 12 posts

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.

#4 Sergio Rodríguez Segura

Sergio Rodríguez Segura


  • Members
  • PipPip
  • 23 posts

Posted 07 April 2014 - 10:20 PM

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


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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users