-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved Required control options - added more validation checks (res…
…olves #277) changed `lzb.editor.control.isValueValid` hook to `lzb.editor.control.validate`
- Loading branch information
Showing
15 changed files
with
298 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -725,6 +725,7 @@ | |
|
||
.components-notice { | ||
margin: 0; | ||
margin-top: 15px; | ||
margin-top: -10px; | ||
margin-bottom: 24px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* WordPress dependencies. | ||
*/ | ||
import { applyFilters } from '@wordpress/hooks'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
import getControlTypeData from '../get-control-type-data'; | ||
|
||
export default function checkControlValidity(val, control) { | ||
let result = false; | ||
|
||
const controlTypeData = getControlTypeData(control.type); | ||
|
||
if ( | ||
controlTypeData && | ||
controlTypeData.restrictions.required_settings && | ||
control.required && | ||
control.required === 'true' | ||
) { | ||
const isValid = val !== '' && typeof val !== 'undefined'; | ||
|
||
// custom validation filter. | ||
const { valid, message } = applyFilters( | ||
'lzb.editor.control.validate', | ||
applyFilters( | ||
`lzb.editor.control.${control.type}.validate`, | ||
{ valid: isValid, message: '' }, | ||
val, | ||
control | ||
), | ||
val, | ||
control | ||
); | ||
|
||
if (!valid) { | ||
result = message || __('This field is required.', 'lazy-blocks'); | ||
} | ||
} | ||
|
||
return result; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.