Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/ValidationsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Validations {
firstPage = 0;
data = {};
insideLoop = false;
isMobile = false;
constructor(element, options) {
this.element = element;
Object.assign(this, options);
Expand All @@ -35,11 +36,13 @@ class Validations {
* Check if element/container is visible.
*/
isVisible() {
// Disable validations if field is hidden
const deviceConfig = this.element.config?.deviceVisibility || {
showForDesktop: true,
showForMobile: true
};
const visibleInDevice =
this.element.visibleInDevice === null || this.element.visibleInDevice === undefined
? true
: this.element.visibleInDevice;
(this.isMobile && deviceConfig.showForMobile) ||
(!this.isMobile && deviceConfig.showForDesktop);
if (!visibleInDevice) {
return false;
}
Expand All @@ -62,7 +65,7 @@ class Validations {
class ArrayOfFieldsValidations extends Validations {
async addValidations(validations) {
for (const item of this.element) {
await ValidationsFactory(item, { screen: this.screen, data: this.data, parentVisibilityRule: this.parentVisibilityRule, insideLoop: this.insideLoop }).addValidations(validations);
await ValidationsFactory(item, { screen: this.screen, data: this.data, parentVisibilityRule: this.parentVisibilityRule, insideLoop: this.insideLoop, isMobile: this.isMobile }).addValidations(validations);
}
}
}
Expand All @@ -75,7 +78,7 @@ class ScreenValidations extends Validations {
// add validations for page 1
if (this.element.config[this.firstPage]) {
pagesValidated = [this.firstPage];
const screenValidations = ValidationsFactory(this.element.config[this.firstPage].items, { screen: this.element, data: this.data });
const screenValidations = ValidationsFactory(this.element.config[this.firstPage].items, { screen: this.element, data: this.data, isMobile: this.isMobile });
await screenValidations.addValidations(validations);
pagesValidated = [];
}
Expand All @@ -96,7 +99,7 @@ class FormNestedScreenValidations extends Validations {
const definition = nestedScreen.config;
let parentVisibilityRule = this.parentVisibilityRule ? this.parentVisibilityRule : this.element.config.conditionalHide;
if (definition && definition[0] && definition[0].items) {
await ValidationsFactory(definition[0].items, { screen: nestedScreen, data: this.data, parentVisibilityRule }).addValidations(validations);
await ValidationsFactory(definition[0].items, { screen: nestedScreen, data: this.data, parentVisibilityRule, isMobile: this.isMobile }).addValidations(validations);
}
}
}
Expand Down Expand Up @@ -146,7 +149,7 @@ class FormLoopValidations extends Validations {
loopField['$each'] = {};
this.checkForSiblings(validations);
const firstRow = (get(this.data, this.element.config.name) || [{}])[0];
await ValidationsFactory(this.element.items, { screen: this.screen, data: {_parent: this.data, ...firstRow }, parentVisibilityRule: this.element.config.conditionalHide, insideLoop: true }).addValidations(loopField['$each']);
await ValidationsFactory(this.element.items, { screen: this.screen, data: {_parent: this.data, ...firstRow }, parentVisibilityRule: this.element.config.conditionalHide, insideLoop: true, isMobile: this.isMobile }).addValidations(loopField['$each']);
}
checkForSiblings(validations) {
const siblings = [];
Expand Down Expand Up @@ -207,7 +210,7 @@ class FormMultiColumnValidations extends Validations {
if (!this.isVisible()) {
return;
}
await ValidationsFactory(this.element.items, { screen: this.screen, data: this.data, parentVisibilityRule: this.element.config.conditionalHide }).addValidations(validations);
await ValidationsFactory(this.element.items, { screen: this.screen, data: this.data, parentVisibilityRule: this.element.config.conditionalHide, isMobile: this.isMobile }).addValidations(validations);
}
}

Expand All @@ -229,7 +232,7 @@ class PageNavigateValidations extends Validations {
if (pagesValidated.length > 0 && !pagesValidated.includes(screenPageId)) {
if (this.screen.config[screenNumber] && this.screen.config[screenNumber].items) {
pagesValidated.push(screenPageId);
await ValidationsFactory(this.screen.config[this.element.config.eventData].items, { screen: this.screen, data: this.data }).addValidations(validations);
await ValidationsFactory(this.screen.config[this.element.config.eventData].items, { screen: this.screen, data: this.data, isMobile: this.isMobile }).addValidations(validations);
}
}
}
Expand Down Expand Up @@ -308,7 +311,7 @@ class FormElementValidations extends Validations {
// Check Device Visibility
let visibleInDevice = true;
try {
const isMobileScreen = this.$root.$children[0].$refs.renderer.definition.isMobile;
const isMobileScreen = this.isMobile;
visibleInDevice =
(isMobileScreen && deviceConfig.showForMobile) ||
(!isMobileScreen && deviceConfig.showForDesktop);
Expand Down Expand Up @@ -375,7 +378,7 @@ class FormElementValidations extends Validations {
};
}
if (this.element.items) {
ValidationsFactory(this.element.items, { screen: this.screen, data: this.data }).addValidations(validations);
ValidationsFactory(this.element.items, { screen: this.screen, data: this.data, isMobile: this.isMobile }).addValidations(validations);
}
}
camelCase(name) {
Expand Down
4 changes: 3 additions & 1 deletion src/components/renderer/form-collection-record-control.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:computed="computed"
:custom-css="customCss"
:watchers="watchers"
:is-mobile="isMobile"
:_parent="_parent"
/>
</template>
Expand Down Expand Up @@ -43,7 +44,8 @@ export default {
collectionmode: {
type: Object
},
taskdraft: Object
taskdraft: Object,
isMobile: {type: Boolean, default: false}
},
data() {
return {
Expand Down
2 changes: 2 additions & 0 deletions src/components/renderer/form-collection-view-control.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:computed="computed"
:custom-css="customCss"
:watchers="watchers"
:is-mobile="isMobile"
:_parent="_parent"
/>
</template>
Expand Down Expand Up @@ -38,6 +39,7 @@ export default {
type: Object
},
taskdraft: Object,
isMobile: {type: Boolean, default: false},
},
data() {
return {
Expand Down
5 changes: 4 additions & 1 deletion src/components/renderer/form-loop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:computed="null"
:custom-css="null"
:watchers="null"
:is-mobile="isMobile"
:is-loop="true"
:debug-context="'Loop #' + loopIndex"
:mode="mode"
Expand Down Expand Up @@ -54,7 +55,9 @@ export default {
VueFormRenderer
},
mixins: [],
props: ["value", "config", "transientData", "name", "mode", "formConfig"],
// Renderer props stay untyped because legacy screens may pass non-canonical runtime types.
// eslint-disable-next-line prettier/prettier
props: ["value", "config", "transientData", "name", "mode", "formConfig", "isMobile"], // NOSONAR
data() {
return {
matrix: [],
Expand Down
2 changes: 2 additions & 0 deletions src/components/renderer/form-nested-screen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:computed="computed"
:custom-css="customCSS"
:watchers="watchers"
:is-mobile="isMobile"
debug-context="Nested Screen"
@css-errors="cssErrors = $event"
:_parent="_parent"
Expand Down Expand Up @@ -42,6 +43,7 @@ export default {
validationData: null,
_parent: null,
ancestorScreens: {type: Array, default: () => []},
isMobile: {type: Boolean, default: false},
},
data() {
return {
Expand Down
5 changes: 4 additions & 1 deletion src/components/renderer/form-record-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
:current-page="form"
:computed="formComputed"
:watchers="formWatchers"
:is-mobile="isMobile"
debug-context="Record List Add"
:_parent="validationData"
@update="updateRowDataNamePrefix"
Expand Down Expand Up @@ -210,6 +211,7 @@
:current-page="form"
:computed="formComputed"
:watchers="formWatchers"
:is-mobile="isMobile"
debug-context="Record List Edit"
:_parent="validationData"
@update="updateRowDataNamePrefix"
Expand Down Expand Up @@ -293,7 +295,8 @@ export default {
"source",
"paginationOption",
"designerMode",
"bgcolormodern"
"bgcolormodern",
"isMobile"
],
data() {
return {
Expand Down
5 changes: 5 additions & 0 deletions src/components/screen-renderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
:vdata="value"
:_parent="_parent || value?._parent"
:_initial-page="currentPage"
:is-mobile="isMobile"
:taskdraft="taskdraft"
@after-submit="afterSubmit"
@submit="submit"
Expand Down Expand Up @@ -71,6 +72,10 @@ export default {
type: String,
default: ""
},
isMobile: {
type: Boolean,
default: false
},
taskdraft: Object
},
data() {
Expand Down
26 changes: 19 additions & 7 deletions src/components/vue-form-renderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:value="data"
:_parent="_parent || data?._parent"
:definition="definition"
:is-mobile="responsiveIsMobile"
:current-page="currentPage"
data-cy="screen-renderer"
:show-errors="showErrors"
Expand Down Expand Up @@ -72,8 +73,7 @@ export default {
config: this.config,
computed: this.computed,
customCss: this.customCss,
watchers: this.watchers,
isMobile: false
watchers: this.watchers
},
formSubmitErrorClass: "",
// watcher URLs
Expand Down Expand Up @@ -114,7 +114,8 @@ export default {
}
},
scrollable: null,
containerObserver: null
containerObserver: null,
containerObserverFrame: null
};
},
computed: {
Expand Down Expand Up @@ -188,6 +189,12 @@ export default {
// Initialize the clipboard module
this.$store.dispatch('clipboardModule/initializeClipboard');
},
beforeDestroy() {
this.containerObserver.disconnect();
if (this.containerObserverFrame) {
cancelAnimationFrame(this.containerObserverFrame);
}
},
methods: {
...mapActions("globalErrorsModule", [
"validate",
Expand Down Expand Up @@ -367,10 +374,15 @@ export default {
this.$emit("update-page-task");
this.$refs.renderer.setCurrentPage(page);
},
onContainerObserver(entries) {
// Control coordinates
const controlEl = entries[0].target.getBoundingClientRect();
this.parseCss();
onContainerObserver() {
if (this.containerObserverFrame) {
cancelAnimationFrame(this.containerObserverFrame);
}
this.containerObserverFrame = requestAnimationFrame(() => {
this.containerObserverFrame = null;
this.checkIfIsMobile();
this.parseCss();
});
},
saveClipboarToLocalStorage(items){
localStorage.setItem("savedClipboard", JSON.stringify(items));
Expand Down
22 changes: 19 additions & 3 deletions src/mixins/DeviceDetector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
export const MAX_MOBILE_WIDTH = 480;
export const originalDevicePixelRatio = window.devicePixelRatio;
export default {
props: {
isMobile: {
type: Boolean,
default: false
}
},
data() {
return {
detectedIsMobile: false
};
},
computed: {
responsiveIsMobile() {
return this.isMobile || this.detectedIsMobile;
}
},
created() {
window.addEventListener("resize", this.resizeHandler);
},
Expand All @@ -17,10 +33,10 @@ export default {
this.checkIfIsMobile();
},
checkIfIsMobile() {
const renderer = document.getElementById("vue-form-renderer");
const renderer = this.$refs.formRendererContainer;
const isModelerInspector = this.data && this.data.$type && this.data.$type.startsWith("bpmn:");
if (this.definition && !isModelerInspector) {
this.definition.isMobile =
if (!isModelerInspector) {
this.detectedIsMobile =
renderer &&
renderer.offsetWidth <= MAX_MOBILE_WIDTH &&
originalDevicePixelRatio === window.devicePixelRatio;
Expand Down
1 change: 1 addition & 0 deletions src/mixins/Json2Vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ export default {
await ValidationsFactory(definition, {
screen: definition,
firstPage,
isMobile: this.isMobile,
data: {
_parent: this._parent,
...this.vdata
Expand Down
6 changes: 3 additions & 3 deletions src/mixins/VisibilityRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Parser } from 'expr-eval';

export default {
methods: {
visibilityRuleIsVisible(rule, name, deviceVisibility) {
const visibility = deviceVisibility || { showForDesktop: true, showForMobile: true, isMobile: false };
visibilityRuleIsVisible(rule, name, deviceVisibility, isMobile = false) {
const visibility = deviceVisibility || { showForDesktop: true, showForMobile: true };
const visibleInDevice =
(visibility.isMobile && visibility.showForMobile) || (!visibility.isMobile && visibility.showForDesktop);
(isMobile && visibility.showForMobile) || (!isMobile && visibility.showForDesktop);

try {
if (rule && rule.trim().length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/mixins/extensions/FormDynamicPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export default {
items: element.items,
}
],
watchers: [],
isMobile: false
watchers: []
};
},

Expand Down Expand Up @@ -57,6 +56,7 @@ export default {
return this.createComponent("ScreenRenderer", {
":definition": this.byRef(nested),
":value": valueExpression,
":is-mobile": "isMobile",
":loop-context": loopContextExpression,
":_parent": "getValidationData()",
":components": this.byRef(this.components),
Expand Down
14 changes: 14 additions & 0 deletions src/mixins/extensions/LoadFieldComponents.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
/* eslint-disable no-param-reassign */
const RESPONSIVE_COMPONENTS = new Set([
"FormLoop",
"FormRecordList",
"FormNestedScreen",
"FormCollectionRecordControl",
"FormCollectionViewControl"
]);

export default {
data() {
return {
popups: []
};
},
methods: {
addResponsiveProperties(properties, componentName) {
if (RESPONSIVE_COMPONENTS.has(componentName)) {
properties[":is-mobile"] = "isMobile";
}
},
searchForRecordList(items) {
items.forEach((item) => {
if (item instanceof Array) {
Expand Down Expand Up @@ -86,6 +99,7 @@ export default {
if (componentName === "FormNestedScreen") {
properties[":_parent"] = "_parent";
}
this.addResponsiveProperties(properties, componentName);
// Add cypress testing tags
if (element.config.name) {
properties["data-cy"] = `screen-field-${element.config.name}`;
Expand Down
Loading
Loading