Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#2093 - Fix red error box on new individual form and ltrim typos and doubling-up of class attribute #18678

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CRM/Core/BAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ public static function addQuickFormElement(

// Search field is always multi-select
if ($search || (self::isSerialized($field) && $widget === 'Select')) {
$fieldAttributes['class'] .= ltrim($fieldAttributes['class'] ?? '' . ' huge');
$fieldAttributes['class'] = ltrim(($fieldAttributes['class'] ?? '') . ' huge');
$fieldAttributes['multiple'] = 'multiple';
$fieldAttributes['placeholder'] = $placeholder;
}
Expand Down Expand Up @@ -794,7 +794,7 @@ public static function addQuickFormElement(

// For all select elements
case 'Select':
$fieldAttributes['class'] .= ltrim($fieldAttributes['class'] ?? '' . ' crm-select2');
$fieldAttributes['class'] = ltrim(($fieldAttributes['class'] ?? '') . ' crm-select2');
if ($field->is_search_range && $search && in_array($field->data_type, $rangeDataTypes)) {
$qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $fieldAttributes);
$qf->add('text', $elementName . '_to', ts('To'), $fieldAttributes);
Expand Down Expand Up @@ -870,7 +870,7 @@ public static function addQuickFormElement(
if (!CRM_Core_Permission::check('access contact reference fields')) {
break;
}
$fieldAttributes['class'] = ltrim($fieldAttributes['class'] ?? '' . ' crm-form-contact-reference huge');
$fieldAttributes['class'] = ltrim(($fieldAttributes['class'] ?? '') . ' crm-form-contact-reference huge');
$fieldAttributes['data-api-entity'] = 'Contact';
$element = $qf->add('text', $elementName, $label, $fieldAttributes, $useRequired && !$search);

Expand Down
35 changes: 35 additions & 0 deletions tests/phpunit/CRM/Contact/Form/IndividualTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,39 @@ public function testOpeningNewIndividualForm() {
$this->assertStringContainsString('<label for="first_name">', $contents);
}

/**
* This is the same as testOpeningNewIndividualForm but with a custom field
* defined. It maybe doesn't need to be a separate test but might make it
* easier to track down problems if one fails but not the other.
*/
public function testOpeningNewIndividualFormWithCustomField() {
$custom_group = $this->customGroupCreate([]);
$custom_field1 = $this->customFieldCreate(['custom_group_id' => $custom_group['id']]);
$custom_field2 = $this->customFieldCreate([
'custom_group_id' => $custom_group['id'],
'label' => 'f2',
'html_type' => 'Select',
// being lazy, just re-use activity type choices
'option_group_id' => 'activity_type',
]);
$custom_field3 = $this->customFieldCreate([
'custom_group_id' => $custom_group['id'],
'label' => 'f3',
'html_type' => 'Radio',
'option_group_id' => 'gender',
]);
$form = new CRM_Contact_Form_Contact();
$form->controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Contact', 'New Individual');

$form->set('reset', '1');
$form->set('ct', 'Individual');

ob_start();
$form->controller->_actions['display']->perform($form, 'display');
$contents = ob_get_contents();
ob_end_clean();

$this->assertStringContainsString('<label for="first_name">', $contents);
}

}