Skip to content

Commit

Permalink
Merge pull request #226 from timekit-io/VS-52235
Browse files Browse the repository at this point in the history
VS-52233 fix for multi select
  • Loading branch information
aliasaria authored Aug 18, 2021
2 parents e13599c + 04aa4be commit 869e3dc
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 55 deletions.
91 changes: 76 additions & 15 deletions dist/booking.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/booking.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/booking.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.7.3",
"version": "2.7.4",
"name": "timekit-booking",
"description": "Make a beautiful embeddable booking widget in minutes",
"main": "dist/booking.min.js",
Expand Down
61 changes: 49 additions & 12 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,27 +489,41 @@ function InitRender(deps) {
return message;
};

var parseHtmlTags = function (field) {
if (field.format === 'label') {
field.title = field.title.replace(/\(\((.*?)\)\)/g, function(match, token) {
var linkTag = token.split(',');
return '<a target="_blank" href="' + linkTag[1].trim() + '">' + linkTag[0].trim() + '</a>';
});
}
return field;
};

// Render customer fields
var renderCustomerFields = function () {
var textTemplate = require('./templates/fields/text.html');
var textareaTemplate = require('./templates/fields/textarea.html');
var labelTemplate = require('./templates/fields/label.html');
var selectTemplate = require('./templates/fields/select.html');
var textareaTemplate = require('./templates/fields/textarea.html');
var checkboxTemplate = require('./templates/fields/checkbox.html');
var multiCheckboxTemplate = require('./templates/fields/multi-checkbox.html');

var fieldsTarget = [];
$.each(getConfig().customer_fields, function (key, field) {
var tmpl = textTemplate;
if (field.format === 'textarea') tmpl = textareaTemplate;
if (field.format === 'label') tmpl = labelTemplate;
if (field.format === 'select') tmpl = selectTemplate;
if (field.format === 'textarea') tmpl = textareaTemplate;
if (field.format === 'checkbox') tmpl = checkboxTemplate;
if (field.format === 'checkbox' && field.enum) tmpl = multiCheckboxTemplate;
if (!field.format) field.format = 'text';
if (key === 'email') field.format = 'email';
var data = $.extend(
{
key: key,
arrowDownIcon: require('!svg-inline-loader!./assets/arrow-down-icon.svg'),
},
field
parseHtmlTags(field)
);
var fieldTarget = $(tmpl.render(data));
fieldsTarget.push(fieldTarget);
Expand Down Expand Up @@ -581,6 +595,15 @@ function InitRender(deps) {
else field.removeClass('bookingjs-form-field--dirty');
});

var requiredCheckboxes = $(form).find('.bookingjs-form-field--checkbox-multi :checkbox[required]');
requiredCheckboxes.change(function() {
if(requiredCheckboxes.is(':checked')) {
requiredCheckboxes.removeAttr('required');
} else {
requiredCheckboxes.attr('required', 'required');
}
});

form.submit(function (e) {
submitBookingForm(this, e, eventData);
});
Expand Down Expand Up @@ -657,11 +680,19 @@ function InitRender(deps) {

var formData = {};
$.each(formElement.serializeArray(), function (i, field) {
formData[field.name] = field.value;
var fieldKey = field.name;
if (!(fieldKey in formData)) {
formData[fieldKey] = field.value;
} else {
if (!Array.isArray(formData[fieldKey])) {
formData[fieldKey] = [formData[fieldKey], field.value];
} else {
formData[fieldKey].push(field.value);
}
}
});

formElement.addClass('loading');

utils.doCallback('submitBookingForm', formData);

// Call create event endpoint
Expand Down Expand Up @@ -762,13 +793,19 @@ function InitRender(deps) {
// Save custom fields in meta object
$.each(getConfig().customer_fields, function (key, field) {
if ($.inArray(key, nativeFields) >= 0) return;
if (field.format === 'checkbox') formData[key] = !!formData[key];
args.customer[key] = formData[key];
args.description +=
(getConfig().customer_fields[key].title || key) +
': ' +
formData[key] +
'\n';
if (field.format === 'checkbox') {
if (!Array.isArray(formData[key])) {
formData[key] = !!formData[key];
}
};
if (field.format !== 'label') {
args.customer[key] = formData[key];
args.description +=
(getConfig().customer_fields[key].title || key) +
': ' +
formData[key] +
'\n';
}
});

if (
Expand Down
31 changes: 22 additions & 9 deletions src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -431,28 +431,41 @@

&-label--checkbox {
display: block;
padding: 10px;
font-size: 1em;
margin-left: 35px;
margin-left: 28px;
color: $textLightColor;
font-family: $fontFamily;
border-bottom: 1px solid $borderColor;

&:disabled {
cursor: not-allowed;
font-style: italic;

&:focus {
box-shadow: inset 0px 0px 1px 1px #D8D8D8;
}
}

input[type=checkbox] {
position: absolute;
left: 3px;
top: 9px;
}
}

&-input--checkbox[type=checkbox] {
position: absolute;
top: 10px;
left: 10px;
width: auto;
margin: 0;
&-field--checkbox-multi {
margin-bottom: 5px;
label {
position: relative;
margin-left: 0;
padding: 2px 0;
border: 0;

input[type=checkbox] {
position: initial;
margin-right: 10px;
}
}
}

// Textarea field
Expand Down Expand Up @@ -485,7 +498,7 @@

&-input-arrow--select {
position: absolute;
top: 45px;
top: 34px;
right: 25px;
width: 12px;
height: 7.42px;
Expand Down
22 changes: 11 additions & 11 deletions src/templates/fields/checkbox.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<div class="bookingjs-form-field bookingjs-form-field--checkbox">
<input
id="input-{{ key }}"
class="bookingjs-form-input--checkbox input-{{ key }}"
type="checkbox"
name="{{ key }}"
value="true"
{{# prefilled }} checked {{/ prefilled }}
{{# readonly }} disabled {{/ readonly }}
{{# required }} required {{/ required }}
/>
<div class="bookingjs-form-field bookingjs-form-field--checkbox">
<label
for="input-{{ key }}"
class="bookingjs-form-label--checkbox label-{{ key }}">
{{ title }}
<input
id="input-{{ key }}"
class="bookingjs-form-input--checkbox input-{{ key }}"
type="checkbox"
name="{{ key }}"
value="true"
{{# prefilled }} checked {{/ prefilled }}
{{# readonly }} disabled {{/ readonly }}
{{# required }} required {{/ required }}
/>
</label>
</div>
7 changes: 7 additions & 0 deletions src/templates/fields/label.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="bookingjs-form-field {{# prefilled }}bookingjs-form-field--dirty{{/ prefilled }}">
<p
for="input-{{ key }}"
class="bookingjs-form-text label-{{ key }}">
{{& title }}
</p>
</div>
20 changes: 20 additions & 0 deletions src/templates/fields/multi-checkbox.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="bookingjs-form-field bookingjs-form-field--checkbox-multi">
<legend class="bookingjs-form-label">{{ title }}</legend>
{{# enum }}
<label
for="input-{{ key }}-{{ . }}"
class="bookingjs-form-label--checkbox label-{{ key }}">
<input
type="checkbox"
value="{{ . }}"
name="{{ key }}"
id="input-{{ key }}-{{ . }}"
{{# prefilled }} checked {{/ prefilled }}
{{# readonly }} disabled {{/ readonly }}
{{# required }} required {{/ required }}
class="bookingjs-form-input--checkbox input-{{ key }}"
/>
{{ . }}
</label>
{{/ enum }}
</div>

0 comments on commit 869e3dc

Please sign in to comment.