Skip to content

Commit a1d2fcd

Browse files
committed
feat: new prop in the input-state "changed"
1 parent 96daed7 commit a1d2fcd

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

plugin/classes/Form.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import deletePropByName from "../utils/delete-prop-by-name";
1414
import getPropFromObject from "../utils/get-prop-from-object";
1515
import {IComparisonResult, searchByComparison, searchChangesByComparison} from "../utils/search-changes-by-comparison";
1616
import debug from "../debug/debug";
17+
import checkNameInObject from "../utils/check-name-in-object";
1718

1819
export default class Form extends EventEmitter implements FormDependence{
1920
static PROVIDE_NAME = 'form-controller';
@@ -130,7 +131,7 @@ export default class Form extends EventEmitter implements FormDependence{
130131
* @description Method check name for including in changes.
131132
* */
132133
checkNameForChangedStatus(dependenceName: string) {
133-
134+
return checkNameInObject(this.changes, dependenceName);
134135
}
135136

136137
/**

plugin/classes/Input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class Input extends EventEmitter {
4040
get changed() {
4141
if (!this.name) return false;
4242
if (!this.parentForm) return false;
43-
return this.parentForm.changed
43+
return this.parentForm.checkNameForChangedStatus(this.name);
4444
}
4545

4646
/**

plugin/hooks/use-input-state.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {onUnmounted, reactive, watch} from "vue";
1+
import {onUnmounted, reactive} from "vue";
22
import Input from "../classes/Input";
33

44
export default function useInputState(name: string, validation: any[] = []) {
@@ -18,16 +18,19 @@ function useInputController(input: Input) {
1818
const state = reactive<{
1919
value: any,
2020
disabled: boolean,
21-
errors: string[]
21+
errors: string[],
22+
changed: boolean
2223
}>({
2324
value: input.value,
2425
disabled: input.disabled,
25-
errors: []
26+
errors: [],
27+
changed: input.changed
2628
})
2729

2830
const controls = {
2931
change: (v:any) => {
3032
state.value = v;
33+
state.changed = true
3134
},
3235
setValues(v: any) {
3336
state.value = v;

0 commit comments

Comments
 (0)