Skip to content

Commit

Permalink
add min max for time input field (#12)
Browse files Browse the repository at this point in the history
* add min max for time input field

* fix condition check

* Exported ACF with export manager plugin

Co-authored-by: Jonatan Hanson <[email protected]>
  • Loading branch information
dannil76 and jonatanhanson authored Dec 20, 2019
1 parent 2f37add commit ae172dd
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 27 deletions.
60 changes: 55 additions & 5 deletions acf-fields/json/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,54 @@
"return_format": "Y-m-d",
"first_day": 1
},
{
"key": "field_5dfb9b0074cfc",
"label": "Min time",
"name": "min_time_value",
"type": "time_picker",
"instructions": "Select minimum time frame",
"required": 0,
"conditional_logic": [
[
{
"field": "field_58eb5547818a0",
"operator": "==",
"value": "time"
}
]
],
"wrapper": {
"width": "50",
"class": "",
"id": ""
},
"display_format": "H:i:s",
"return_format": "H:i:s"
},
{
"key": "field_5dfbf8a374cfe",
"label": "Max time",
"name": "max_time_value",
"type": "time_picker",
"instructions": "Select maximum time frame",
"required": 0,
"conditional_logic": [
[
{
"field": "field_58eb5547818a0",
"operator": "==",
"value": "time"
}
]
],
"wrapper": {
"width": "50",
"class": "",
"id": ""
},
"display_format": "H:i:s",
"return_format": "H:i:s"
},
{
"key": "field_58eb5614c5514",
"label": "Required",
Expand Down Expand Up @@ -1874,7 +1922,7 @@
"class": "",
"id": ""
},
"message": "<div style=\"margin: 5px 0 15px;\r\n background: #f1f1f157;\r\n border-left: 4px solid #b2b500;\r\n box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);\r\n padding: 10px;\">Conditional fields must be a multi-choise field that is required to fill in and lacks conditional arguments. Note that you may not get email notfications if the requirements aren't fulfilled.<\/div>",
"message": "<div style=\"margin: 5px 0 15px;\r\n background: #f1f1f157;\r\n border-left: 4px solid #b2b500;\r\n box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);\r\n padding: 10px;\">Conditional fields must be a multi-choise field that is required to fill in and lacks conditional arguments. Note that you may not get email notfications if the requirements aren't fulfilled.<\/div>",
"new_lines": "",
"esc_html": 0
},
Expand Down Expand Up @@ -2291,12 +2339,14 @@
"id": ""
},
"choices": {
"form-submissions": "Formul\u00e4rsvar",
"form-submissions": "Form submissions",
"event": "H\u00e4ndelse",
"ticket": "\u00c4rende",
"listing": "Lista",
"lovprogram": "Lovprogram",
"johan-test123": "Johan-test123"
"johan-test123": "Johan-test123",
"projekt": "Projekt",
"idea": "Ideas"
},
"default_value": [
"form-submissions"
Expand Down Expand Up @@ -2410,7 +2460,7 @@
},
{
"key": "field_5b3c8d3f4e20a",
"label": "GDPR komplience meddelande",
"label": "GDPR komplience meddelande",
"name": "gdpr_complience_notice",
"type": "true_false",
"instructions": "Inneh\u00e5ller information om hur personlig data hanteras.",
Expand Down Expand Up @@ -2547,7 +2597,7 @@
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 1,
"active": true,
"description": ""
}]

94 changes: 72 additions & 22 deletions acf-fields/php/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
'allow_custom' => 0,
'save_custom' => 0,
'default_value' => array(
0 => __('firstname', 'modularity-form-builder'),
1 => __('lastname', 'modularity-form-builder'),
2 => __('email', 'modularity-form-builder'),
0 => 'firstname',
1 => 'lastname',
2 => 'email',
),
'layout' => 'vertical',
'toggle' => 0,
Expand Down Expand Up @@ -95,9 +95,9 @@
'allow_custom' => 0,
'save_custom' => 0,
'default_value' => array(
0 => __('firstname', 'modularity-form-builder'),
1 => __('lastname', 'modularity-form-builder'),
2 => __('email', 'modularity-form-builder'),
0 => 'firstname',
1 => 'lastname',
2 => 'email',
),
'layout' => 'vertical',
'toggle' => 0,
Expand Down Expand Up @@ -351,7 +351,7 @@
'class' => '',
'id' => '',
),
'default_value' => __('Message', 'modularity-form-builder'),
'default_value' => 'Message',
'placeholder' => '',
'prepend' => '',
'append' => '',
Expand Down Expand Up @@ -716,6 +716,54 @@
'first_day' => 1,
),
8 => array(
'key' => 'field_5dfb9b0074cfc',
'label' => __('Min time', 'modularity-form-builder'),
'name' => 'min_time_value',
'type' => 'time_picker',
'instructions' => __('Select minimum time frame', 'modularity-form-builder'),
'required' => 0,
'conditional_logic' => array(
0 => array(
0 => array(
'field' => 'field_58eb5547818a0',
'operator' => '==',
'value' => 'time',
),
),
),
'wrapper' => array(
'width' => '50',
'class' => '',
'id' => '',
),
'display_format' => 'H:i:s',
'return_format' => 'H:i:s',
),
9 => array(
'key' => 'field_5dfbf8a374cfe',
'label' => __('Max time', 'modularity-form-builder'),
'name' => 'max_time_value',
'type' => 'time_picker',
'instructions' => __('Select maximum time frame', 'modularity-form-builder'),
'required' => 0,
'conditional_logic' => array(
0 => array(
0 => array(
'field' => 'field_58eb5547818a0',
'operator' => '==',
'value' => 'time',
),
),
),
'wrapper' => array(
'width' => '50',
'class' => '',
'id' => '',
),
'display_format' => 'H:i:s',
'return_format' => 'H:i:s',
),
10 => array(
'key' => 'field_58eb5614c5514',
'label' => __('Required', 'modularity-form-builder'),
'name' => 'required',
Expand All @@ -734,7 +782,7 @@
'ui_on_text' => '',
'ui_off_text' => '',
),
9 => array(
11 => array(
'key' => 'field_59b69ae3e2abd',
'label' => __('Conditional logic', 'modularity-form-builder'),
'name' => 'conditional_logic',
Expand All @@ -753,7 +801,7 @@
'ui_on_text' => '',
'ui_off_text' => '',
),
10 => array(
12 => array(
'key' => 'field_59b69ae6e2abe',
'label' => __('Conditonal field', 'modularity-form-builder'),
'name' => 'conditonal_field',
Expand Down Expand Up @@ -785,7 +833,7 @@
'return_format' => 'value',
'placeholder' => '',
),
11 => array(
13 => array(
'key' => 'field_5a18388b007a2',
'label' => __('Custom post type title', 'modularity-form-builder'),
'name' => 'custom_post_type_title',
Expand Down Expand Up @@ -1761,7 +1809,7 @@
'class' => '',
'id' => '',
),
'default_value' => __('Skicka', 'modularity-form-builder'),
'default_value' => 'Skicka',
'maxlength' => '',
'placeholder' => '',
'prepend' => '',
Expand Down Expand Up @@ -1897,10 +1945,10 @@
'id' => '',
),
'message' => __('<div style="margin: 5px 0 15px;
background: #f1f1f157;
border-left: 4px solid #b2b500;
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
padding: 10px;">Conditional fields must be a multi-choise field that is required to fill in and lacks conditional arguments. Note that you may not get email notfications if the requirements aren\'t fulfilled.</div>', 'modularity-form-builder'),
background: #f1f1f157;
border-left: 4px solid #b2b500;
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
padding: 10px;">Conditional fields must be a multi-choise field that is required to fill in and lacks conditional arguments. Note that you may not get email notfications if the requirements aren\'t fulfilled.</div>', 'modularity-form-builder'),
'new_lines' => '',
'esc_html' => 0,
),
Expand Down Expand Up @@ -2321,15 +2369,17 @@
'id' => '',
),
'choices' => array(
'form-submissions' => 'Formulärsvar',
'form-submissions' => 'Form submissions',
'event' => __('Händelse', 'modularity-form-builder'),
'ticket' => __('Ärende', 'modularity-form-builder'),
'listing' => __('Lista', 'modularity-form-builder'),
'lovprogram' => 'Lovprogram',
'johan-test123' => 'Johan-test123',
'lovprogram' => __('Lovprogram', 'modularity-form-builder'),
'johan-test123' => __('Johan-test123', 'modularity-form-builder'),
'projekt' => 'Projekt',
'idea' => 'Ideas',
),
'default_value' => array(
0 => __('form-submissions', 'modularity-form-builder'),
0 => 'form-submissions',
),
'allow_null' => 0,
'multiple' => 0,
Expand Down Expand Up @@ -2440,7 +2490,7 @@
),
29 => array(
'key' => 'field_5b3c8d3f4e20a',
'label' => __('GDPR komplience meddelande', 'modularity-form-builder'),
'label' => __('GDPR komplience meddelande', 'modularity-form-builder'),
'name' => 'gdpr_complience_notice',
'type' => 'true_false',
'instructions' => __('Innehåller information om hur personlig data hanteras.', 'modularity-form-builder'),
Expand Down Expand Up @@ -2478,7 +2528,7 @@
'class' => '',
'id' => '',
),
'default_value' => __('I det här formuläret samlar vi in personuppgifter om dig för att [det formuläret ska användas till]. Uppgifterna kommer inte att hanteras för något annat syfte, och kommer att raderas när [ärendet är avslutat]. Läs om hur Helsingborgs stad hanterar personuppgifter.', 'modularity-form-builder'),
'default_value' => 'I det här formuläret samlar vi in personuppgifter om dig för att [det formuläret ska användas till]. Uppgifterna kommer inte att hanteras för något annat syfte, och kommer att raderas när [ärendet är avslutat]. Läs om hur Helsingborgs stad hanterar personuppgifter.',
'placeholder' => '',
'maxlength' => '',
'rows' => '',
Expand Down Expand Up @@ -2577,7 +2627,7 @@
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'active' => true,
'description' => '',
));
}
Expand Down
3 changes: 3 additions & 0 deletions source/php/Module/views/fields-editable/input.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class="large-text"
@if ($field['value_type'] == 'date')
min="{{ SanitizeData::formatDate($field['min_value']) }}"
max="{{ SanitizeData::formatDate($field['max_value']) }}"
@elseif (($field['value_type'] == 'time'))
@if (!empty($field['min_time_value'])) min="{{ trim($field['min_time_value']) }}" @endif
@if (!empty($field['max_time_value'])) max="{{ trim($field['max_time_value']) }}" @endif
@elseif (in_array($field['value_type'], array('number', 'range')))
min="{{ trim($field['min_value']) }}"
max="{{ trim($field['max_value']) }}"
Expand Down
4 changes: 4 additions & 0 deletions source/php/Module/views/fields/input.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<div class="grid mod-form-field" {!! $field['conditional_hidden'] !!}>
<div class="grid-md-12">
<div class="form-group">

<label for="{{ $module_id }}-input-{{ sanitize_title($field['label']) }}">
{{ $field['label'] }}
@if ($field['required'])
Expand All @@ -30,6 +31,9 @@
@if ($field['value_type'] == 'date')
min="{{ SanitizeData::formatDate($field['min_value']) }}"
max="{{ SanitizeData::formatDate($field['max_value']) }}"
@elseif ($field['value_type'] == 'time')
@if (!empty($field['min_time_value'])) min="{{ trim($field['min_time_value']) }}" @endif
@if (!empty($field['max_time_value'])) max="{{ trim($field['max_time_value']) }}" @endif
@elseif (in_array($field['value_type'], array('number', 'range')))
@if (!empty(trim($field['min_value']))) min="{{ trim($field['min_value']) }}" @endif
@if (!empty(trim($field['max_value']))) max="{{ trim($field['max_value']) }}" @endif
Expand Down

0 comments on commit ae172dd

Please sign in to comment.