Skip to content

Commit

Permalink
🔙 from #669 - Show label for input checkbox widget (#670)
Browse files Browse the repository at this point in the history
* Show label for input checkbox widget (#669)

* 🐛Show label when edit input

* 🐛 Need to check if value is Boolena. In this case no need to convert in string

* 🐛 Every time an input change, nee to set this.feature property with current input value. Chnage in one point of code changeInput method) No need to set on GlobalTabs or other methods. this.statefeature is referred to this feature

* Show label for input checkbox widget (#669)

* 🐛Show label when edit input

* 🐛 Need to check if value is Boolena. In this case no need to convert in string

* 🐛 Every time an input change, nee to set this.feature property with current input value. Chnage in one point of code changeInput method) No need to set on GlobalTabs or other methods. this.statefeature is referred to this feature
  • Loading branch information
volterra79 authored Oct 4, 2024
1 parent 4b1dc14 commit f08e9a3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
10 changes: 4 additions & 6 deletions src/app/gui/form/formservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function FormService() {

/**
* Force update state of the service
* (eg. setted on a child to parent form service relation)
* (e.g., setted on a child to parent form service relation)
*/
this.state = {
layerid: layer.getId(),
Expand All @@ -124,9 +124,9 @@ function FormService() {
isnew,
valid: true, // global form validation state. True at beginning
update: feature.isNew(), // set update in case or not is a new feature
// when input change will be update
// when input change will be updated
tovalidate: {},
feature,
feature: this.feature, //need to get feature cloned,
componentstovalidate: {},
footer,
ready: false
Expand Down Expand Up @@ -180,6 +180,7 @@ proto.setReady = function(bool = false) {
* @param input
*/
proto.changeInput = function(input) {
this.feature.set(input.name, input.value);
if (true === this.listenChangeInput) {
this.evaluateFilterExpressionFields(input);
this.evaluateDefaultExpressionFields(input);
Expand Down Expand Up @@ -225,7 +226,6 @@ proto.setUpdate = function(bool = false, options = {}) {
proto.evaluateDefaultExpressionFields = function(input = {}) {
const filter = this.default_expression_fields_dependencies[input.name];
if (filter) {
this.feature.set(input.name, input.value);
filter.forEach(dependency_field => {
FormService._getDefaultExpression({
parentData: this.parentData,
Expand All @@ -247,8 +247,6 @@ proto.evaluateFilterExpressionFields = function(input = {}) {
if (filter) {
// on form service inititalization `filter_expression` option has
// `referencing_fields` or `referenced_columns` from another layer
const fieldForm = this._getField(input.name);
if (fieldForm) { this.feature.set(fieldForm.name, fieldForm.value) }
filter.forEach(dependency_field => {
FormService._getFilterExpression({
parentData: this.parentData,
Expand Down
16 changes: 6 additions & 10 deletions src/app/gui/inputs/checkbox/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ const { inherit, base } = require('utils');
const Service = require('gui/inputs/service');

function CheckBoxService(options = {}) {
const value = options.state.input.options.values.find(value => value.checked === false);
options.validatorOptions = {
values: options.state.input.options.values.map(value => value)
};
if (options.state.value === null && !options.state.forceNull) { options.state.value = value.value }
base(this, options);
}

Expand All @@ -16,22 +14,20 @@ const proto = CheckBoxService.prototype;

proto.convertCheckedToValue = function(checked) {
checked = [null, undefined].includes(checked) ? false : checked;
const option = this.state.input.options.values.find(value => checked === value.checked);
this.state.value = option.value;

this.state.value = [true, false].includes(this.state.value) //check if is a boolean value
? (this.state.input.options.values.find(v => checked === v.checked) || {}).value //get boolean value
: `${(this.state.input.options.values.find(v => checked === v.checked) || {}).value}`; // Need to convert it to string because server return always string value
return this.state.value;
};

proto.convertValueToChecked = function() {
const valueToCheck = this.state.value;
if ([null, undefined].includes(valueToCheck)) { return false }
let option = this.state.input.options.values.find(value => valueToCheck == value.value);
if ([null, undefined].includes(this.state.value)) { return false }
let option = this.state.input.options.values.find(v => this.state.value == v.value);
if (undefined === option) {
option = this.state.input.options.values.find(value => false === value.checked);
option = this.state.input.options.values.find(v => false === v.checked);
this.state.value = option.value;
}
return option.checked;
};


module.exports = CheckBoxService;
3 changes: 1 addition & 2 deletions src/components/GlobalTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@
const field = this.fields.find(f => c === f.name);
this.unwatch.push(
this.$watch(() => field.value,
async (v) => {
this.feature.set(field.name, v);
async () => {
await this.setVisibility(tab);
})
)
Expand Down
7 changes: 3 additions & 4 deletions src/components/InputCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
return {
value: null,
label: null,
id: getUniqueDomId() // new id
id: getUniqueDomId() // new id
}
},
methods: {
Expand All @@ -58,9 +58,8 @@ export default {
}
},
mounted() {
if (this.state.forceNull) {
this.setLabel();
}
//Need to set label and value
this.stateValueChanged();
}
};
</script>

0 comments on commit f08e9a3

Please sign in to comment.