_comment.php
4 months ago
_db.php
4 months ago
_hidden.php
4 months ago
_label.php
4 months ago
_row.php
4 months ago
attachment.php
4 months ago
checkbox.php
4 months ago
cleditor.php
4 months ago
codemirror.php
4 months ago
color.php
4 months ago
currency.php
4 months ago
date.php
4 months ago
datetime.php
4 months ago
email.php
4 months ago
link.php
4 months ago
number.php
4 months ago
oembed.php
4 months ago
password.php
4 months ago
phone.php
4 months ago
radio.php
4 months ago
select.php
4 months ago
slider.php
4 months ago
slug.php
4 months ago
text.php
4 months ago
textarea.php
4 months ago
time.php
4 months ago
tinymce.php
4 months ago
website.php
4 months ago
number.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | // Don't load directly. |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | die( '-1' ); |
| 6 | } |
| 7 | |
| 8 | // phpcs:ignoreFile WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound |
| 9 | |
| 10 | $field_number = PodsForm::field_loader( 'number' ); |
| 11 | |
| 12 | $attributes = array(); |
| 13 | $attributes['type'] = 'text'; |
| 14 | $attributes['value'] = $value; |
| 15 | $attributes['tabindex'] = 2; |
| 16 | $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options ); |
| 17 | |
| 18 | global $wp_locale; |
| 19 | |
| 20 | if ( '9999.99' === pods_v( 'number_format', $options ) ) { |
| 21 | $thousands = ','; |
| 22 | $dot = '.'; |
| 23 | } elseif ( '9999,99' === pods_v( 'number_format', $options ) ) { |
| 24 | $thousands = '.'; |
| 25 | $dot = ','; |
| 26 | } elseif ( '9.999,99' === pods_v( 'number_format', $options ) ) { |
| 27 | $thousands = '.'; |
| 28 | $dot = ','; |
| 29 | } else { |
| 30 | $thousands = $wp_locale->number_format['thousands_sep']; |
| 31 | $dot = $wp_locale->number_format['decimal_point']; |
| 32 | } |
| 33 | $regex_test = '^[0-9\\' . implode( '\\', array_filter( array( $dot, $thousands ) ) ) . '\\-]$'; |
| 34 | $regex_replace = '[^0-9\\' . implode( '\\', array_filter( array( $dot, $thousands ) ) ) . '\\-]'; |
| 35 | ?> |
| 36 | <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?>/> |
| 37 | <script> |
| 38 | jQuery( function ( $ ) { |
| 39 | $( 'input#<?php echo esc_js( $attributes['id'] ); ?>' ).on( 'blur', function () { |
| 40 | if ( !/<?php echo esc_js( $regex_test ); ?>/.test( $( this ).val() ) ) { |
| 41 | var newval = $( this ) |
| 42 | .val() |
| 43 | .replace( /<?php echo esc_js( $regex_replace ); ?>/g, '' ); |
| 44 | $( this ).val( newval ); |
| 45 | } |
| 46 | } ); |
| 47 | } ); |
| 48 | </script> |
| 49 |