Skip to content

[4.2] Fix radio form field required validation#39578

Merged
roland-d merged 2 commits intojoomla:4.2-devfrom
joomdonation:fix_radio_field_required_validation
Jan 9, 2023
Merged

[4.2] Fix radio form field required validation#39578
roland-d merged 2 commits intojoomla:4.2-devfrom
joomdonation:fix_radio_field_required_validation

Conversation

@joomdonation
Copy link
Copy Markdown
Contributor

Pull Request for Issue #39496.

Summary of Changes

Base on code at https://github.com/joomla/joomla-cms/blob/4.2-dev/build/media_source/system/js/fields/validate.es6.js#L192 and https://github.com/joomla/joomla-cms/blob/4.2-dev/build/media_source/system/js/fields/validate.es6.js#L194 , to validate a radio form field as required, the fieldset element in radio form field layout must has class attribute contains radio . The element also need to have required attribute or required in it's class.

Since required is not a valid attribute for fieldset element, I set class="required radio" when the field is required to address the issue.

Testing Instructions

  1. Open the file administrator/components/com_content/forms/article.xml, add the below code after id field:
<field name="status" id="status" type="radio" class="btn-group"
			label="HISTORY_STATUS" 
			description="HISTORY_STATUS" 
		        required="true"
			default="0"
		>
			<option value="1">In Process</option>
  			<option value="2">Return</option>
			<option value="3">Sent</option>
		</field>
  1. Edit the file administrator/components/com_content/tmpl/article/edit.php, add this line of code below after this line https://github.com/joomla/joomla-cms/blob/4.2-dev/administrator/components/com_content/tmpl/article/edit.php#L66 to render the new field
<div class="row"><?php echo $this->form->getInput('status'); ?></div>
  1. Create a new article, try to save the article without choosing an option from the new field above

Actual result BEFORE applying this Pull Request

The form is submitted even the radio field is a required field.

Expected result AFTER applying this Pull Request

Form is not submitted, an error message like below will be displayed:

The form cannot be submitted as it's missing required data.
Please correct the marked fields and try again.

Link to documentations

Please select:

  • No documentation changes for docs.joomla.org needed
  • No documentation changes for manual.joomla.org needed

@samuelagus
Copy link
Copy Markdown

I have tested this item ✅ successfully on 6481d66


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39578.

Comment thread layouts/joomla/form/field/radio/buttons.php
@heelc29
Copy link
Copy Markdown
Contributor

heelc29 commented Jan 9, 2023

I have tested this item ✅ successfully on 6481d66


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39578.

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 9, 2023

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39578.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jan 9, 2023
@roland-d roland-d merged commit a1a135d into joomla:4.2-dev Jan 9, 2023
@roland-d
Copy link
Copy Markdown
Contributor

roland-d commented Jan 9, 2023

Thank you

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jan 9, 2023
@roland-d roland-d added this to the Joomla! 4.2.7 milestone Jan 9, 2023
@joomdonation joomdonation deleted the fix_radio_field_required_validation branch January 9, 2023 18:54
charvimehradu pushed a commit to charvimehradu/joomla-cms that referenced this pull request Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants