⚠ 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

Why readonly field dont work if is required field?



jbscps

jbscps
  • profile picture
  • Member

Posted 28 May 2012 - 14:56 PM

Hi,

why I get field required message validation on edit form? the field tid is readonly on edit form.


$this->grocery_crud->fields('tid','local_id','nome','data_instalacao');

$this->grocery_crud->required_fields('tid','local_id','nome','data_instalacao');

if( $operation == 'add') //work
{
$this->grocery_crud->set_rules('tid', 'ID','required|is_unique[carcacas.tid]');
}
else if ( $operation == 'edit') //get validation required error
{
$this->grocery_crud->change_field_type('tid','readonly'); //show me field readonly
}

this work on add form, but when edit form show readonly field and validation error message "The field ID is required!".

I'm using current version.

thanks,

groceryCRUD is fantastic, congratulations

best regards

kenvogt

kenvogt
  • profile picture
  • Member

Posted 28 May 2012 - 16:27 PM

Do not list tid in required_fields(), your set_rules() statement covers it.

jbscps

jbscps
  • profile picture
  • Member

Posted 28 May 2012 - 18:01 PM

thanks for reply, I try this but dont work too, i need required field in add method, when I set required in set_rules, dont work validation and crash application.



$this->grocery_crud->fields('tid','local_id','nome','data_instalacao');
if( $operation == 'add')
{
$this->grocery_crud->set_rules('tid', 'ID','required|is_unique[carcacas.tid]');
$this->grocery_crud->set_rules('local_id', 'Local','required');
$this->grocery_crud->set_rules('nome', 'Nome','required');
$this->grocery_crud->set_rules('data_instalacao', 'Data Instalação','required');
//validation dont work on commit form
}
else if ( $operation == 'edit')
{
$this->grocery_crud->set_rules('local_id', 'Local','required');
$this->grocery_crud->set_rules('nome', 'Nome','required');
$this->grocery_crud->set_rules('data_instalacao', 'Data Instalação','required');
$this->grocery_crud->change_field_type('tid','readonly');
//validation dont work on commit form
}


i need only see tid field readonly in edit mode and required validation only add method, I dont understand when set_rules replace rules of required_fields function, I tried before and after...

thanks

best regards

web-johnny

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

Posted 28 May 2012 - 20:16 PM

Well this is the right way to do it but you also need this:


if( $operation == 'add' || $operation == 'insert' || $operation == 'insert_validation')//Change this line here <-----------------------------------------------------
{
$this->grocery_crud->set_rules('tid', 'ID','required|is_unique[carcacas.tid]');
$this->grocery_crud->set_rules('local_id', 'Local','required');
$this->grocery_crud->set_rules('nome', 'Nome','required');
$this->grocery_crud->set_rules('data_instalacao', 'Data Instala&ccedil;&atilde;o','required');
}
elseif( $operation == 'edit' || $operation == 'update' || $operation == 'update_validation') //Change this line here <-----------------------------------------------------
{
$this->grocery_crud->set_rules('local_id', 'Local','required');
$this->grocery_crud->set_rules('nome', 'Nome','required');
$this->grocery_crud->set_rules('data_instalacao', 'Data Instala&ccedil;&atilde;o','required');
$this->grocery_crud->change_field_type('tid','readonly');
}

jbscps

jbscps
  • profile picture
  • Member

Posted 28 May 2012 - 20:44 PM

thanks johnny and kenvogt, working! =)

best regards!