Skip to content

Commit

Permalink
Merge branch 'enh/preview-step' into release-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
buttflattery committed Feb 5, 2020
2 parents 0b14016 + 24b5958 commit 7a54af7
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/FormWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public function createFormWizard()
'type' => self::STEP_TYPE_PREVIEW,
'title' => 'Final Preview',
'description' => 'Final Preview of all Steps',
'formInfoText' => 'Click any of the steps below to edit them',
'formInfoText' => 'Review information below and click to change',
],
]
);
Expand Down Expand Up @@ -755,7 +755,7 @@ public function createBody($index, $formInfoText, $step)
$isSkipable = ArrayHelper::getValue($step, 'isSkipable', false);

//check if tabular step
$isTabularStep = $stepType == self::STEP_TYPE_TABULAR;
$isTabularStep = $stepType === self::STEP_TYPE_TABULAR;

//tabular rows limit
$limitRows = ArrayHelper::getValue($step, 'limitRows', self::ROWS_UNLIMITED);
Expand Down
4 changes: 2 additions & 2 deletions src/assetbundles/bs3/FormWizardAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class FormWizardAsset extends ThemeBase
];

public $css = [
'css/animate.css',
'css/shake.css',
'css/animate.min.css',
'css/shake.min.css',
'css/smart_wizard.min.css',
'css/icons-theme.min.css',
];
Expand Down
8 changes: 8 additions & 0 deletions src/assets/css/animate.min.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/assets/css/shake.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/assets/css/smart_wizard.css
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@
cursor: not-allowed;
}

.notify-target {
box-shadow: 0 0 5px rgba(81, 203, 238, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 1px solid rgba(81, 203, 238, 1);
-webkit-transition: all 0.30s ease-in-out;
-moz-transition: all 0.30s ease-in-out;
-ms-transition: all 0.30s ease-in-out;
-o-transition: all 0.30s ease-in-out;
}

@media screen and (max-width: 768px) {
.sw-theme-default>.nav-tabs>li {
float: none !important;
Expand Down
2 changes: 1 addition & 1 deletion src/assets/css/smart_wizard.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 42 additions & 18 deletions src/assets/js/formwizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ $.formwizard = {
btnFinish.removeClass("hidden d-none");
btnPrev.removeClass("disabled hidden d-none");
//call preview step if enabled
$.formwizard.helper.addPreviewStep(wizardContainerId);
$.formwizard.previewStep.add(wizardContainerId);
} else {
btnPrev.removeClass("disabled");
btnNext.removeClass("disabled hidden d-none");
Expand All @@ -167,7 +167,10 @@ $.formwizard = {
currentIndex: function (form) {
return $(form + " ul.step-anchor>li.active").index();
},
addPreviewStep: (wizardContainerId) => {

},
previewStep: {
add: (wizardContainerId) => {
let formwizardOptions = $.formwizard.options;
let formId = $(wizardContainerId).closest('form').attr('id');
let fragment = document.createDocumentFragment();
Expand All @@ -183,20 +186,22 @@ $.formwizard = {

if (formwizardOptions.hasOwnProperty(formId) && formwizardOptions[formId].enablePreview) {
let fields = $.formwizard.fields[formId];

fields.forEach(function (stepFields, step) {
let stepPreviewContainer = document.createElement("div");
stepPreviewContainer.setAttribute('class', classListGroup + ' preview-container');
stepPreviewContainer.dataset.step = step;
let rowHtml = '<h4 class="' + classListGroupHeading + '">Step ' + parseInt(step + 1) + '</h4>';
stepFields.forEach(function (fieldName, index) {
let inputLabel = $.formwizard.helper.getpreviewInputLabel(fieldName);
let inputValue = $.formwizard.helper.getpreviewInputValue(formId, fieldName);
let inputLabel = $.formwizard.previewStep.getLabel(fieldName);
let inputValue = $.formwizard.previewStep.getValue(formId, fieldName);
let stepData = {
label: inputLabel == '' ? 'NA' : inputLabel,
value: inputValue == '' ? 'NA' : inputValue
"label": inputLabel == '' ? 'NA' : inputLabel,
"value": inputValue == '' ? 'NA' : inputValue,
"target": fieldName
};

rowHtml += $.formwizard.helper.previewTemplate(stepData, bsVersion, formwizardOptions[formId]);
rowHtml += $.formwizard.previewStep.getTemplate(stepData, bsVersion, formwizardOptions[formId]);
});

stepPreviewContainer.innerHTML = rowHtml;
Expand All @@ -207,35 +212,57 @@ $.formwizard = {
$(".preview-button").on('click', function (e) {
let stepNo = $(this).closest('div.preview-container').data('step');
$.formwizard.formNavigation.goToStep(wizardContainerId, stepNo);
$.formwizard.previewStep.highlightTarget($(this).val());
});
}
},
getpreviewInputLabel: (fieldName) => {
getLabel: (fieldName) => {
let text = $('#' + fieldName).siblings('label').text();
if (text !== '') {
return text;
}
return $('#' + fieldName).attr("placeholder");
},
getpreviewInputValue: (formId, fieldName) => {
getValue: (formId, fieldName) => {
let inputType = $('#' + formId + ' #' + fieldName);

if (inputType.is("select")) {
// <select> element.
return $('#' + formId + ' #' + fieldName + ' option:selected').text();
} else {
// <textarea> element.
return inputType.val();
}

if (inputType.is('div') && inputType.attr('role') == 'radiogroup') {
let radio = inputType.find('input:checked');
return (radio.length) ? radio.val() : '';
}

if (inputType.is('div')) {
let checkboxes = inputType.find('input:checked');
let choices = '';
checkboxes.each(function (index, checkbox) {
choices += $(checkbox).val() + ',';
});
return choices;
}

// <textarea> <input> element.
return inputType.val();

},
previewTemplate: (params, bsVersion, formwizardOptions) => {
getTemplate: (params, bsVersion, formwizardOptions) => {
let bsClass = bsVersion == 4 ? 'list-group-item-action' : '';
return `<button type="button" class="list-group-item ${formwizardOptions.classListGroupItem} ${bsClass} preview-button">
return `<button type="button" class="list-group-item ${formwizardOptions.classListGroupItem} ${bsClass} preview-button" value="${params.target}">
<span class="badge ${formwizardOptions.classListGroupBadge}">
${params.label}
</span>
${params.value}
</button>`;
},
highlightTarget: function (target) {
$('.field-' + target).addClass('notify-target');
setTimeout(function () {
$('.field-' + target).removeClass('notify-target');
}, 2000);
}
},
formValidation: {
Expand Down Expand Up @@ -748,9 +775,6 @@ $.formwizard = {
$.formwizard.persistence.storageFields['step-' + stepNumber].fields[fieldId] = $("#" + formId + " #" + fieldId).is(":checked");
}
}



},
checkbox: (fieldId) => {
let isCheckBoxList = $('#' + formId + " #" + fieldId).attr('name').match(/\[\]$/g);
Expand All @@ -771,7 +795,7 @@ $.formwizard = {
$.formwizard.persistence.storageFields['step-' + stepNumber].fields[rowId][fieldId] = $("#" + formId + " #" + fieldId).is(":checked");
}
} else {
if (isCheckBoxList.length) {
if (isCheckBoxList && isCheckBoxList.length) {
let checkboxList = $("input[name='" + $("#" + formId + " #" + fieldId).attr('name') + "']");
checkboxList.each(function (index, element) {
//add fields to the local fieldstorage property
Expand Down
Loading

0 comments on commit 7a54af7

Please sign in to comment.