Jump to content


Why readonly field dont work if is required field?

readonly required edit

  • Please log in to reply
4 replies to this topic

#1 jbscps

jbscps

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 28 May 2012 - 02: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

#2 kenvogt

kenvogt

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts

Posted 28 May 2012 - 04:27 PM

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

#3 jbscps

jbscps

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 28 May 2012 - 06: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

#4 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,099 posts
  • LocationLondon

Posted 28 May 2012 - 08: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');
}

Posted Image

#5 jbscps

jbscps

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 28 May 2012 - 08:44 PM

thanks johnny and kenvogt, working! =)

best regards!





Also tagged with one or more of these keywords: readonly, required, edit

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users