Skip to content

Commit

Permalink
Updated form validation documentation (#280)
Browse files Browse the repository at this point in the history
`$forms_module->field_types['tel']` returns null and it can't remove the action. To make it work I updated that part to use `$forms_module->fields_registrar->get( 'tel' )`.
  • Loading branch information
emreerkan authored Dec 23, 2024
1 parent 7105bdc commit ae7ba19
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/hooks/form-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Tel match this format XXX-XXX-XXXX, i.e. 123-456-7890
function elementor_form_tel_field_validation( $field, $record, $ajax_handler ) {
// Remove native validation
$forms_module = \ElementorPro\Plugin::instance()->modules_manager->get_modules( 'forms' );
remove_action( 'elementor_pro/forms/validation/tel', [ $forms_module->field_types['tel'], 'validation' ] );
remove_action( 'elementor_pro/forms/validation/tel', [ $forms_module->fields_registrar->get( 'tel' ), 'validation' ], 10, 3 );

// Run your own validation, ex:
if ( empty( $field['value'] ) ) {
Expand All @@ -78,7 +78,7 @@ add_action( 'elementor_pro/forms/validation/tel', 'elementor_form_tel_field_vali
function elementor_form_tel_field_rendering( $item, $item_index, $form ) {
// Remove native render
$forms_module = \ElementorPro\Plugin::instance()->modules_manager->get_modules( 'forms' );
remove_action( 'elementor_pro/forms/render_field/tel', [$forms_module->field_types['tel'] , 'field_render' ], 10, 3 );
remove_action( 'elementor_pro/forms/render_field/tel', [ $forms_module->fields_registrar->get( 'tel' ), 'field_render' ], 10, 3 );

// Add custom render ex:
$form->add_render_attribute( 'input' . $item_index, 'class', 'elementor-field-textual' );
Expand Down

0 comments on commit ae7ba19

Please sign in to comment.