pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.07k stars 264 forks source link

Numeric field softformat truncates leading AND trailing zeros #5281

Closed cip247 closed 5 years ago

cip247 commented 5 years ago

Describe the bug I have a custom post type where I need to use numbers with 3 to 4 decimals. So I have set up a number field (decimals 4, softformat yes). The page is in german so I am using , as a divider. The tooltip for softformat reads „ remove trailing decimals (0)“ which is exacly the functionality that I need. So in my understanding it should be 0,02 instead of 0,0200 when I enter 0,02. But if softformat is enabled it seems that it is truncating the leading zeros AND the trailing zeros instead of the supposed trailing. So if I enter 0,02 and save only 02 remains. This gets then displayed in frontend as 2. When disabling softformat it gets correctly displayed but it adds the missing zeros, so 0,03 becomes 0,0300. It would be great if it wold then stay 0,03 (which is what I expected from softformat).

To Reproduce Steps to reproduce the behavior: create new pods Custom Typ add field Plain Number, decimals 4, softformat yes

Expected behavior If entered 0,02 -> 0,02 If entered 0,023 -> 0,023 If entered 0,0234 -> 0,0234

Screenshots bildschirmfoto 2019-01-20 um 18 19 49

I have this checkbox checked since I need the removal of TRAILING zeros

bildschirmfoto 2019-01-20 um 18 17 30

without soft format if adds missing zeros so if I enter 0,02 it becomes 0,0200

Pods Version

2.7.12

WordPress Environment

WordPress Version: 5.0.3 PHP Version: 7.2.14 MySQL Version: 5.6.42 Server Software: Apache/2.4.37 (Unix) Your User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:64.0) Gecko/20100101 Firefox/64.0 Session Save Path: 2;/var/tmp Session Save Path Exists: No Session Save Path Writeable: No Session Max Lifetime: 1440 Opcode Cache: Apc: No Memcached: No OPcache: Yes Redis: No Object Cache: APC: No APCu: No Memcache: No Memcached: No Redis: No WPDB Prefix: wp_ WP Multisite Mode: No WP Memory Limit: 128M Current Memory Usage: 23,710M Current Memory Usage (real): 26,000M Pods Network-Wide Activated: No Pods Install Location: /mnt/web407/e1/22/59558522/htdocs/WordPress_02/wp-content/plugins/pods/ Pods Tableless Mode Activated: No Pods Light Mode Activated: No Currently Active Theme: OceanWP Currently Active Plugins: Elementor: 2.3.8 Elementor Pro: 2.3.1 Google Analytics Dashboard for WP (GADWP): 5.3.7 Jetpack by WordPress.com: 6.9 Ocean Extra: 1.5.0 PayPal Donations: 1.9.5 Pods - Custom Content Types and Fields: 2.7.12 Really Simple SSL: 3.1.3 TablePress: 1.9.1 Wordfence Security: 7.1.20 WP DSGVO Tools (GDPR): 2.2.8 Yoast SEO: 9.4

Pods Package Export (helpful!)

{"meta":{"version":"2.7.12","build":1548347934},"pods":{"939":{"id":939,"name":"portoperiode","label":"Portoperioden","description":"","type":"post_type","storage":"meta","object":"","alias":"","fields":{"first_day":{"id":940,"name":"first_day","label":"Ersttag","description":"Ersttag der Periode","help":"","class":"","type":"date","weight":0,"pick_object":"","pick_val":"","sister_id":"","required":"1","date_type":"format","date_format":"dmy_dot","date_allow_empty":"1","date_html5":"0","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","date_repeatable":"0","date_format_custom":"","date_format_custom_js":""},"last_day":{"id":941,"name":"last_day","label":"Letzttag","description":"Letzttag der Periode","help":"","class":"","type":"date","weight":1,"pick_object":"","pick_val":"","sister_id":"","required":"0","date_type":"format","date_format":"dmy_dot","date_allow_empty":"1","date_html5":"0","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","date_repeatable":"0","date_format_custom":"","date_format_custom_js":""},"days":{"id":942,"name":"days","label":"Tage","description":"Dauer der Portoperiode in Tagen","help":"","class":"","type":"number","weight":2,"pick_object":"","pick_val":"","sister_id":"","required":"0","number_format_type":"number","number_format":"i18n","number_decimals":"0","number_format_soft":"0","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","number_repeatable":"0","number_placeholder":""},"printed_matter":{"id":943,"name":"printed_matter","label":"Printed Matter","description":"Gebühr für Drucksache (Printed Matter)","help":"","class":"","type":"number","weight":3,"pick_object":"","pick_val":"","sister_id":"","required":"0","number_format_type":"number","number_format":"i18n","number_decimals":"4","number_format_soft":"1","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","number_repeatable":"0","number_placeholder":""},"surface_1st_20g":{"id":944,"name":"surface_1st_20g","label":"Land- & Seeweg erste 20g","description":"Gebühr Land- & Seeweg erste 20g","help":"","class":"","type":"number","weight":4,"pick_object":"","pick_val":"","sister_id":"","required":"0","number_format_type":"number","number_format":"i18n","number_decimals":"3","number_format_soft":"1","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","number_repeatable":"0","number_placeholder":""},"surface_succ_20g":{"id":945,"name":"surface_succ_20g","label":"Land- & Seeweg folgende 20g","description":"Gebühr Land- & Seeweg folgende 20g","help":"","class":"","type":"number","weight":5,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","number_format_type":"number","number_format":"i18n","number_decimals":"4","number_format_soft":"1","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","number_repeatable":"0","number_placeholder":""},"airmail_surcharge":{"id":946,"name":"airmail_surcharge","label":"Luftpost Zuschlag","description":"Zuschlag für Luftpost","help":"","class":"","type":"number","weight":6,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","number_format_type":"number","number_format":"i18n","number_decimals":"4","number_format_soft":"1","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","number_repeatable":"0","number_placeholder":""},"airmail_per_x_g":{"id":947,"name":"airmail_per_x_g","label":"Zuschlag per x g","description":"Zuschlag für Luftpost per x g","help":"","class":"","type":"number","weight":7,"pick_object":"","pick_val":"","sister_id":"","required":"0","number_format_type":"number","number_format":"i18n","number_decimals":"0","number_format_soft":"0","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","number_repeatable":"0","number_placeholder":""},"registered":{"id":948,"name":"registered","label":"Einschreiben","description":"","help":"","class":"","type":"number","weight":8,"pick_object":"","pick_val":"","sister_id":"","required":"0","number_format_type":"number","number_format":"i18n","number_decimals":"3","number_format_soft":"1","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","number_repeatable":"0","number_placeholder":""},"ar":{"id":951,"name":"ar","label":"Empfangsbestätigung","description":"Gebühr für Empfangsbestätigung","help":"","class":"","type":"number","weight":9,"pick_object":"","pick_val":"","sister_id":"","required":"0","number_format_type":"number","number_format":"i18n","number_decimals":"4","number_format_soft":"1","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","number_repeatable":"0","number_placeholder":""},"express":{"id":952,"name":"express","label":"Express","description":"Gebühr für Express","help":"","class":"","type":"number","weight":10,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","number_format_type":"number","number_format":"i18n","number_decimals":"4","number_format_soft":"1","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","number_repeatable":"0","number_placeholder":""},"registered_express":{"id":953,"name":"registered_express","label":"Einschreiben Express","description":"Gebühr für Einschreiben Express","help":"","class":"","type":"number","weight":11,"pick_object":"","pick_val":"","sister_id":"","required":"0","unique":"0","number_format_type":"number","number_format":"i18n","number_decimals":"4","number_format_soft":"1","number_step":"1","number_min":"0","number_max":"100","number_max_length":"12","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","number_repeatable":"0","number_placeholder":""},"international":{"id":949,"name":"international","label":"International","description":"Rate für internationalen Versand","help":"","class":"","type":"boolean","weight":12,"pick_object":"","pick_val":"","sister_id":"","required":"1","pick_post_status":["publish"],"boolean_format_type":"radio","boolean_yes_label":"International","boolean_no_label":"National","default_value":"Yes","admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0"},"currency":{"id":950,"name":"currency","label":"Währung","description":"Währung für Rate","help":"","class":"","type":"text","weight":13,"pick_object":"","pick_val":"","sister_id":"","required":"0","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","text_repeatable":"0","text_placeholder":""}},"show_in_menu":"1","label_singular":"Portoperiode","public":"1","show_ui":"1","supports_title":"1","supports_editor":"0","label_add_new":"Neue Portoperiode","label_add_new_item":"Neue Portoperiode hinzufügen","label_new_item":"Neue Portoperiode","label_edit_item":"Portoperiode bearbeiten","label_view_item":"Portoperiode ansehen","label_view_items":"Portoperioden ansehen","label_all_items":"Alle Portoperioden","label_search_items":"Portoperiode suchen","label_not_found":"Keine Portoperiode gefunden","label_archives":"Portoperioden","label_filter_items_list":"Portoperioden Filter Liste","label_items_list_navigation":"Portoperioden Liste Navigation","label_items_list":"Portoperioden Liste","label_item_published":"Portoperiode veröffentlicht.","label_item_published_privately":"Portoperiode privat veröffentlicht.","label_item_reverted_to_draft":"Portoperiode auf Entwurf zurückgestellt.","label_item_scheduled":"Portoperiode geplant","label_item_updated":"Portoperiode aktualisiert","publicly_queryable":"1","exclude_from_search":"0","capability_type":"post","capability_type_custom":"portoperiode","capability_type_extra":"1","has_archive":"0","hierarchical":"0","rewrite":"1","rewrite_with_front":"1","rewrite_feeds":"0","rewrite_pages":"1","query_var":"1","can_export":"1","default_status":"draft","supports_author":"0","supports_thumbnail":"0","supports_excerpt":"0","supports_trackbacks":"0","supports_custom_fields":"0","supports_comments":"0","supports_revisions":"0","supports_page_attributes":"0","supports_post_formats":"0","supports_jetpack_publicize":"0","supports_jetpack_markdown":"0","built_in_taxonomies_category":"0","built_in_taxonomies_elementor_font_type":"0","built_in_taxonomies_elementor_library_type":"0","built_in_taxonomies_gebiet":"0","built_in_taxonomies_link_category":"0","built_in_taxonomies_post_tag":"0","show_in_nav_menus":"1","show_in_admin_bar":"1","pfat_enable":"0","pfat_run_outside_loop":"0","pfat_append_single":"append","pfat_filter_single":"the_content","pfat_append_archive":"append","pfat_filter_archive":"the_content","rest_enable":"0","read_all":"0","write_all":"0","menu_icon":"dashicons-pressthis","built_in_taxonomies_merkmal":"0","built_in_taxonomies_jahr":"1","built_in_taxonomies_destination":"1"}}}

Additional context I really like pods and the flexibility it gives me! Keep on the great work ! Thanks from Germany.

Possible Workaround Setting the field as text displays it correctly.

JLNNN commented 5 years ago

Maybe this is also related to my reported problem => #5215

pglewis commented 5 years ago

Note that everything saves fine in the DB so this issue is in the formatting on load.

pglewis commented 5 years ago

The immediate fix could present an issue for back-compat. The saved data will always have leading zeroes so if you previously were seeing .025 displayed, it'll then be 0.025 as there is no way to determine if the leading zero was manually entered or a side-effect of the save.

I think the best fix might be separate options for trimming leading and trailing zeroes.

sc0ttkclark commented 5 years ago

Moving to 2.7.14

JoryHogeveen commented 5 years ago

@cip247 Please test #5439 and let us know if this fixes your issue! @JLNNN It seems you have a different issue which I will address separately.