Skip to content

Commit

Permalink
Merge pull request #392 from workarea-commerce/WORKAREA-221-validate-…
Browse files Browse the repository at this point in the history
…date-in-timeline-report-custom-events

Validate Date In Timeline Report Custom Events
  • Loading branch information
Ben Crouse committed Mar 16, 2020
2 parents 18d8440 + 985c536 commit 5423000
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ WORKAREA.registerModule('datetimepickerFields', (function () {
},

injectUI = function($input) {
var placeholder = JST['workarea/admin/templates/datetime_picker']({
var required = !_.isEmpty($input.attr('required')) ? 'required' : '',
placeholder = JST['workarea/admin/templates/datetime_picker']({
id: $input.attr('id'),
initialDateTime: parseDate($input),
fieldSuffixes: WORKAREA.config.datetimepickerFields.fieldSuffixes,
name: $input.attr('id')
name: $input.attr('id'),
required: required
});

// Prevents UI being injected twice on browser back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
<div class="grid__cell grid__cell--50-at-medium">
<div class='property'>
<label for="<%= name + fieldSuffixes.date %>" class='property__name'><%= I18n.t('workarea.admin.js.datetime_picker.date') %></label>
<input type="text" name="<%= name + fieldSuffixes.date %>" id="<%= name + fieldSuffixes.date %>" class="text-box" data-datetimepicker-field-date-input='' placeholder='YYYY-MM-DD' pattern='^\d{4}-\d{2}-\d{2}$' />
<input type="text" name="<%= name + fieldSuffixes.date %>" id="<%= name + fieldSuffixes.date %>" class="text-box" data-datetimepicker-field-date-input='' placeholder='YYYY-MM-DD' pattern='^\d{4}-\d{2}-\d{2}$' <%= required %> />
</div>
</div>
<div class="grid__cell grid__cell--50-at-medium">
<div class='property'>
<label for="<%= name + fieldSuffixes.hours %>" class='property__name'><%= I18n.t('workarea.admin.js.datetime_picker.time') %></label>
<select id="<%= name + fieldSuffixes.hours %>" name="<%= name + fieldSuffixes.hours %>">
<select id="<%= name + fieldSuffixes.hours %>" name="<%= name + fieldSuffixes.hours %>" <%= required %>>
<% for ( var i = 1; i <= 12; i++ ) {
var selected = ( initialDateTime.hours == i ) ? 'selected' : '';
%>
<option value="<%= i %>" <%= selected %> ><%= i %></option>
<% } %>
</select>

<select id="<%= name + fieldSuffixes.minutes %>" name="<%= name + fieldSuffixes.minutes %>">
<select id="<%= name + fieldSuffixes.minutes %>" name="<%= name + fieldSuffixes.minutes %>" <%= required %>>
<% for ( var i = 0; i < 60; i++ ) {
if (i < 10) { i = '0' + i }
var selected = ( initialDateTime.minutes == i ) ? 'selected' : '';
Expand All @@ -27,7 +27,7 @@
<% } %>
</select>

<select id="<%= name + fieldSuffixes.ampm %>" name="<%= name + fieldSuffixes.ampm %>">
<select id="<%= name + fieldSuffixes.ampm %>" name="<%= name + fieldSuffixes.ampm %>" <%= required %>>
<option value="am" <%= initialDateTime.ampm === 'am' ? 'selected' : '' %> >am</option>
<option value="pm" <%= initialDateTime.ampm === 'pm' ? 'selected' : '' %> >pm</option>
</select>
Expand Down
2 changes: 1 addition & 1 deletion admin/app/views/workarea/admin/reports/timeline.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
= text_field_tag 'custom_event[name]', nil, class: 'text-box', required: true
.property
.box.box--rounded.box--padded
= hidden_field_tag 'custom_event[occurred_at]', nil, data: { datetimepicker_field: { inline: true } }
= hidden_field_tag 'custom_event[occurred_at]', nil, required: true, data: { datetimepicker_field: { inline: true } }
.align-center
= submit_tag t('workarea.admin.reports.timeline.add_custom_event'), class: 'button button--create button--small'

Expand Down

0 comments on commit 5423000

Please sign in to comment.