Skip to content

Commit f10a155

Browse files
committed
scoumbourdis#38: required_field doesn't work for relation_n_n fields
1 parent 1f2c005 commit f10a155

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

application/libraries/Grocery_CRUD.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,10 +825,19 @@ protected function db_update_validation()
825825
foreach($edit_fields as $edit_field)
826826
{
827827
$field_name = $edit_field->field_name;
828-
if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) )
829-
{
830-
$this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required');
828+
829+
// Workaround as Codeigniter set_rules has a bug with array and doesn't work with required fields.
830+
// We are basically doing the check here!
831+
if (array_key_exists($field_name, $this->relation_n_n) && in_array($field_name, $required_fields)) {
832+
if (!array_key_exists($field_name, $_POST)) {
833+
// This will always throw an error!
834+
$this->set_rules($field_name, $field_types[$field_name]->display_as, 'required');
835+
}
836+
} else if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) {
837+
$this->set_rules($field_name, $field_types[$field_name]->display_as, 'required');
831838
}
839+
840+
832841
}
833842
}
834843

change_log.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
v1.6.3
22
- #465: Translation for Spanish Uruguay by @mlopezcoria
33
- #468: Remove PHP 7.3 warnings
4+
- #38: required_field doesn't work for relation_n_n fields
45
v 1.6.2
56
- #442: Searching in grid with value 0 is not working
67
- #458: Updated Lithuanian language by @dgvirtual

0 commit comments

Comments
 (0)