⚠ 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

API - getState and setRelation



darkstalker

darkstalker
  • profile picture
  • Member

Posted 12 April 2017 - 23:21 PM

Hi everyone,

i need to use setRelation in AddForm only. I don't want it to work in the Main state.

If i use getState() and use setRelation in the "AddForm" or "Insert" state, it doesn't work. It seem that "AddForm" or "Insert"state are both too late because i need the setRelation to work before the form get visualized.

Maybe there is a state triggered before the form show up on the screen ?

 

The reason i want it to work in AddForm only is because i want to be able to search that field in the column of the main grid.

 

In the community version this was not a problem because the setRelation fields where normally searchable.

The new system with Select box is really useful but sometimes it is not the best soluction. In my case, in the grid i need to search but in AddForm is better to have a selection box.

 

Someone can help me ? Thanks


dbarros

dbarros
  • profile picture
  • Member

Posted 14 April 2017 - 14:15 PM

I have the same situation, is there anyway to get some insight on how the getState() is working. Are there only certain methods that can be used based on the state?   

 if ($state = 'EditForm') {
            $assets->fieldType("accountId", "readonly");
            $assets->fieldType("routingNumber", "readonly");
        }

This does not seem to be working. 


web-johnny

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

Posted 04 September 2017 - 04:14 AM

Hello @darkstalker, @dbarros,

 

As you are asking two different questions, I will answer with two different answers :)

@darkstalker you can use the brand new functions: fieldTypeEditForm, fieldTypeAddForm or fieldTypeReadForm there are also examples to see the usage at the documentation. It is really straight forward.

 

@dbarros you can use: readOnlyEditFields and you can have the expected results with a simple line of code:

 

$crud->readOnlyEditFields(['accountId', 'routingNumber']);

darkstalker

darkstalker
  • profile picture
  • Member

Posted 05 September 2017 - 07:14 AM

 

@darkstalker you can use the brand new functions: fieldTypeEditForm, fieldTypeAddForm or fieldTypeReadForm there are also examples to see the usage at the documentation. It is really straight forward.

 

 

Hi Johnny !

 

I think that doesn't work for my case because i need setRelation on the same field.

 

Example :

 

I have a table with products. Each product have a serial number ( that is the key of the table).

 

In every view ( main grid, add, edit....) i need to filter this field with setRelation because i need to hide some products based on the user that is logged in.

 

So, if i use the setRelation, the serial number become dropdown_search but in the main grid that is very unconfortable because i have thousands of products and i cannot search the field in the column.

 

In can only search in the global search field in the top right search field.

 

If i try to use fieldType or fieldTypeAddForm etc.... i cannot figure out how to obtain what i want because the setRelation conflict with that functions.

 

Thanks for the attention