⚠ 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

BUG: requiredFields doesn't work inside getState()



larasmith

larasmith
  • profile picture
  • Member

Posted 16 July 2018 - 07:32 AM

Hello Everyone!

 

I have a crud that has a clone feature.

During cloning, I set some of the cloned fields to read-only because I wanted to make the user see what he is currently cloning.

Here is the current code:

$ff = ['gr_SemId', 'gr_AY', 'gr_Name', 'gr_Flooring', 'gr_Ceiling'];
$crud->requiredFields($ff);

$crud->setClone();
$crud->readOnlyCloneFields(['gr_Name']);

 

 

It does what it needs to do but during Save, It says: "Remark is required". I believe that read-only fields should be automatically excluded in the required fields.

 

I did try to make a workaround by using getState:

$state = $crud->getState();

if ($state == 'Insert') { 
$crud->requiredFields(['gr_Flooring']); 
} else if ($state == 'Update') { 
$crud->requiredFields(['gr_Ceiling']); 
}

 

but nothing happens. It seems that it doesn't work. I also tried getting the actual state and using it:

 

$state = $crud->getState();
if ($state == 'CloneForm') {
$crud->requiredFields(['gr_Flooring']);
} else if ($state == 'EditForm') {
$crud->requiredFields(['gr_Ceiling']);
}

still no luck. I hope this bug gets fixed on the next release.

 

Any known workarounds for this one?

Your help is highly appreciated. Thanks!