Permalink
Browse files

Auto-calculate size of date field depending on input date format

  • Loading branch information...
1 parent f6705d6 commit b3e1921762888475237372a5ba16b024935e052a @winskie winskie committed Jan 11, 2017
@@ -1316,6 +1316,30 @@ function date_input( $field_name, $field_value, $field_label, $field_params = ar
return $m[0];
}' ), $date_format );
+ // Get max length of each date component
+ $js_date_length = preg_replace_callback( '~(\\\)?(\w)~', create_function( '$m', '
+ if( $m[1] == "\\\" ) return "\\\".$m[0]; // leave escaped
+ switch( $m[2] )
+ {
+ case "d": return "xx"; // day, 01-31
+ case "j": return "XX"; // day, 1-31
+ case "l": return "XXXXXXXXX"; // weekday (name)
+ case "D": return "XXX"; // weekday (abbr)
+ case "S": return "";
+
+ case "e": return ""; // weekday letter, not supported
+
+ case "m": return "XX"; // month, 01-12
+ case "n": return "XX"; // month, 1-12
+ case "F": return "XXXXXXXXX"; // full month name; "name or abbr" in date.js
+ case "M": return "XXX"; // month name abbr
+
+ case "y": return "XX"; // year, 00-99
+ case "Y": return "XXXX"; // year, XXXX
+ default:
+ return "_";
+ }' ), $date_format );
+
$field_params['type'] = 'text';
if( param_has_error( $field_name )
@@ -1360,7 +1384,7 @@ function date_input( $field_name, $field_value, $field_label, $field_params = ar
if( !isset($field_params['size']) )
{ // Get size out of $date_format if not explicitly set
- $field_params['size'] = strlen( $js_date_format );
+ $field_params['size'] = strlen( $js_date_length );
}
/*
Oops, something went wrong.
@@ -3536,8 +3536,8 @@ a.btn.action_icon.hoverlink {
display: inline-block;
margin: 0 0 2px;
}
-.form-horizontal #itemform_extra .form-group input[type=text],
-.form-horizontal #itemform_edit_timestamp .form-group input[type=text] {
+.form-horizontal #itemform_extra .form-group input[type=text]:not( #item_issue_date ),
+.form-horizontal #itemform_edit_timestamp .form-group input[type=text]:not( #item_issue_date ) {
max-width: 85px;
}
.form-horizontal #itemform_extra td,
Oops, something went wrong.
@@ -1926,8 +1926,8 @@ a.btn.action_icon.hoverlink {
display: inline-block;
margin: 0 0 2px;
}
-.form-horizontal #itemform_extra .form-group input[type=text],
-.form-horizontal #itemform_edit_timestamp .form-group input[type=text] {
+.form-horizontal #itemform_extra .form-group input[type=text]:not( #item_issue_date ),
+.form-horizontal #itemform_edit_timestamp .form-group input[type=text]:not( #item_issue_date ) {
max-width: 85px;
}
.form-horizontal #itemform_extra td,
@@ -239,7 +239,7 @@ a.btn.action_icon {
.form-group {
display: inline-block;
margin: 0 0 2px;
- input[type=text] {
+ input[type=text]:not( #item_issue_date ) {
max-width: 85px;
}
}
@@ -621,7 +621,7 @@ fieldset ul {
#itemform_content .panel-title > a.post_type_link:hover {
color: #23527c;
}
-#itemform_extra input {
+#itemform_extra input:not( #item_issue_date ) {
max-width: 80px;
}
#itemform_extra > div.fieldset > label {
@@ -655,7 +655,7 @@ fieldset ul {
}
}
#itemform_extra {
- input {
+ input:not( #item_issue_date ) {
max-width: 80px;
}
> div.fieldset > label {
Oops, something went wrong.

0 comments on commit b3e1921

Please sign in to comment.