Skip to content

Commit

Permalink
fix: properties panel control for int field type
Browse files Browse the repository at this point in the history
well 0 is false in JS, so hurray.
updated logic to check for int field type and return the value 0 if present instead of going to parent properties
  • Loading branch information
maharshivpatel committed May 16, 2024
1 parent 06bc652 commit d712abd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
18 changes: 12 additions & 6 deletions print_designer/public/js/print_designer/frappeControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ export const makeFeild = ({
obj_value = formatValue(object, propertyName, isStyle);

if (
(value || fieldtype == "Color") &&
formatValue(object, propertyName, isStyle) != value
(!(typeof value == "undefined" || value === null) ||
fieldtype == "Color") &&
obj_value != value
) {
object[propertyName] = value;
onChangeCallback && onChangeCallback(value);
Expand Down Expand Up @@ -93,10 +94,15 @@ export const makeFeild = ({
MainStore.frappeControls[name].$input[0].onfocus = () => {
MainStore.frappeControls[name].$input.select();
MainStore.frappeControls[name].$input.one("blur", () => {
MainStore.frappeControls[name].$input.val(
MainStore.frappeControls[name].value ||
MainStore.frappeControls[name].last_value
);
let value = MainStore.frappeControls[name].value;
if (
typeof value == "undefined" ||
value === null ||
(fieldtype == "Int" && !Number.isInteger(value))
) {
value = MainStore.frappeControls[name].last_value;
}
MainStore.frappeControls[name].$input.val(value);
});
};
} else if (fieldtype === "Select") {
Expand Down
28 changes: 22 additions & 6 deletions print_designer/public/js/print_designer/store/MainStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ export const useMainStore = defineStore("MainStore", {
object.selectedColumn?.["style"] ||
object[styleEditMode];
},
isValidValue: (state) => (value) => {
if (typeof value == "string") {
return value.length != 0;
} else if (typeof value == "number") {
return true;
}
return false;
},
getCurrentStyle: (state) => (propertyName) => {
let object = state.getCurrentElementsValues[0];
if (!object) return state.getGlobalStyleObject?.[propertyName];
Expand All @@ -426,12 +434,20 @@ export const useMainStore = defineStore("MainStore", {
});
let styleEditMode = mapper[object.styleEditMode];
if (propertyName != "backgroundColor") {
return (
object.selectedDynamicText?.[styleEditMode][propertyName] ||
object.selectedColumn?.["style"][propertyName] ||
object[styleEditMode][propertyName] ||
state.getGlobalStyleObject[propertyName]
);
if (
state.isValidValue(object.selectedDynamicText?.[styleEditMode][propertyName])
) {
return object.selectedDynamicText?.[styleEditMode][propertyName];
}
if (state.isValidValue(object.selectedColumn?.["style"][propertyName])) {
return object.selectedColumn?.["style"][propertyName];
}
if (state.isValidValue(object[styleEditMode][propertyName])) {
return object[styleEditMode][propertyName];
}
if (state.isValidValue(state.getGlobalStyleObject[propertyName])) {
return state.getGlobalStyleObject[propertyName];
}
} else {
// we need to check if empty string incase it is background color and set as transparent
if (typeof object.selectedDynamicText?.[styleEditMode][propertyName] == "string") {
Expand Down

0 comments on commit d712abd

Please sign in to comment.