@@ -249,6 +249,13 @@ public function validate() {
249
249
$ this ->add_error ( sprintf ( __ ( '%s requires at least one selection ' , 'jetpack-forms ' ), $ field_label ) );
250
250
}
251
251
break ;
252
+ case 'number ' :
253
+ // Make sure the number address is valid
254
+ if ( ! is_numeric ( $ field_value ) ) {
255
+ /* translators: %s is the name of a form field */
256
+ $ this ->add_error ( sprintf ( __ ( '%s requires a number ' , 'jetpack-forms ' ), $ field_label ) );
257
+ }
258
+ break ;
252
259
default :
253
260
// Just check for presence of any text
254
261
if ( ! is_string ( $ field_value ) || ! strlen ( trim ( $ field_value ) ) ) {
@@ -910,6 +917,25 @@ public function render_date_field( $id, $label, $value, $class, $required, $requ
910
917
return $ field ;
911
918
}
912
919
920
+ /**
921
+ * Return the HTML for the number field.
922
+ *
923
+ * @param int $id - the ID.
924
+ * @param string $label - the label.
925
+ * @param string $value - the value of the field.
926
+ * @param string $class - the field class.
927
+ * @param bool $required - if the field is marked as required.
928
+ * @param string $required_field_text - the text in the required text field.
929
+ * @param string $placeholder - the field placeholder content.
930
+ *
931
+ * @return string HTML
932
+ */
933
+ public function render_number_field ( $ id , $ label , $ value , $ class , $ required , $ required_field_text , $ placeholder ) {
934
+ $ field = $ this ->render_label ( 'number ' , $ id , $ label , $ required , $ required_field_text );
935
+ $ field .= $ this ->render_input_field ( 'number ' , $ id , $ value , $ class , $ placeholder , $ required );
936
+ return $ field ;
937
+ }
938
+
913
939
/**
914
940
* Return the HTML for the default field.
915
941
*
@@ -1102,6 +1128,9 @@ public function render_field( $type, $id, $label, $value, $class, $placeholder,
1102
1128
case 'consent ' :
1103
1129
$ field .= $ this ->render_consent_field ( $ id , $ field_class );
1104
1130
break ;
1131
+ case 'number ' :
1132
+ $ field .= $ this ->render_number_field ( $ id , $ label , $ value , $ field_class , $ required , $ required_field_text , $ field_placeholder );
1133
+ break ;
1105
1134
default : // text field
1106
1135
$ field .= $ this ->render_default_field ( $ id , $ label , $ value , $ field_class , $ required , $ required_field_text , $ field_placeholder , $ type );
1107
1136
break ;
0 commit comments