handleTextChange = async (value) => {
const { option } = this.props;
let update = true;
let isValid = true;
if (value.length > option.maxLength && option.maxLength > 0) {
update = false;
}
if (update && option.entryPattern && value.length > 0) {
const { allowedCharacterRegex, appends } = option.entryPattern;
const regex = new RegExp(allowedCharacterRegex);
const lastCharacter = value.slice(-1);
if (Option.getValue(option).length < value.length) {
update = regex.test(lastCharacter) || lastCharacter === "-";
const appendedCharacter = appends.find(
(x) => x.position === value.length,
);
if (appendedCharacter) {
value += appendedCharacter.text;
}
}
}
if (update) {
if (option.regex && value.length) {
const regex = new RegExp(option.regex);
isValid = regex.test(value);
}
if (isValid && option.checkDenom > 0) {
isValid = (currency(value) * 1000) % (option.checkDenom * 1000) === 0;
}
console.log("handle text change options: ", this.props.option);
console.log("handle text change value: ", value);
const updatedOptions = {
...this.props.option,
isValid,
defaultText: value,
}
console.log("Updated options: ", updatedOptions);
await this.props.onChange(
updatedOptions,
value,
);
}
};
class OptionsList extends React.Component {
onChange = (option, value) => {
console.log("Options list option: ", option)
console.log("Options list value: ", value)
this.props.onChange(option, value);
};
class ManageInstallationModal extends React.Component {
saveDebounce = null;
removeDebounce = null;
closeModal = () => {
ManageInstallationModalAction.callback();
ManageInstallationModalAction.reset();
};
onChange = (key, option, value, installationId) => {
const { isRemove } = this.props.data;
const controls = [...this.props.data[key]];
const index = controls.findIndex((control) => option.code === control.code);
console.log(`Key: ${key}, option: ${option}, value: ${value}, installationID: ${installationId}`);
console.log('onChange option: ', option);
console.log('onChange value: ', value);
controls[index] = { ...option, value };
ManageInstallationModalAction.dispatch({
...this.props.data,
[key]: controls,
}).then(() => {
if (!option.doRefresh) return;
if (isRemove) {
if (!this.removeDebounce) {
this.removeDebounce = _.debounce(
() => this.handleRemove(false),
1000,
);
}
this.removeDebounce();
} else {
if (!this.saveDebounce) {
this.saveDebounce = _.debounce(
() => this.handleSave(false, installationId),
1000,
);
}
this.saveDebounce();
}
});
};
why is the onChange in managinstallationmodal not having the same option as the other functions that is calling it?