Last active
October 23, 2024 11:07
-
-
Save Crocoblock/2e9b8c7c86a627b60127251abbf0a951 to your computer and use it in GitHub Desktop.
JetFormBuilder currency mask
This file contains hidden or 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
<?php | |
class JFB_Currency_Mask { | |
private $processed = false; | |
public function __construct() { | |
add_filter( 'jet-form-builder/render/text-field/attributes', array( $this, 'process_fields' ), 10, 2 ); | |
} | |
public function process_fields( $attrs, $field ) { | |
if ( $this->processed ) { | |
return $attrs; | |
} | |
if ( false !== strpos( $field->block_type->block_attrs['class_name'], 'currency-mask' ) ) { | |
wp_enqueue_script( | |
'jet-form-builder-inputmask', | |
\Jet_Form_Builder\Plugin::instance()->plugin_url( 'assets/lib/inputmask/jquery.inputmask.min.js' ), | |
array( 'jquery' ), | |
\Jet_Form_Builder\Plugin::instance()->get_version(), | |
true | |
); | |
$this->add_inline_script(); | |
$this->processed = true; | |
} | |
return $attrs; | |
} | |
private function add_inline_script() { | |
ob_start(); | |
?> | |
jQuery( document ).on( 'jet-form-builder/after-init', function( $ ) { | |
jQuery( "input.currency-mask" ).inputmask( { | |
prefix: "$ ", | |
groupSeparator: ",", | |
autoUnmask: true, | |
alias: "numeric", | |
digits: 2, | |
digitsOptional: 1, | |
max: 9999999 | |
} ); | |
} ); | |
<?php | |
$script = ob_get_clean(); | |
wp_add_inline_script( | |
'jet-form-builder-inputmask', | |
$script, | |
'after' | |
); | |
} | |
} | |
new JFB_Currency_Mask(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1: Does not return the value on it JFB_FIELD::fieldname the way we used the mask on the field.
2: unable to submit the form anymore. This error is painted in console Uncaught TypeError: Cannot read properties of null (reading 'charAt')
3: The form gets submit. But no display shows. "Form submitted"
4: i am using jetform builder pdf addon. and setup a redirection to the pdf after submissions, but it seems not redirecting now.