inertia-bootstrap-forms 1.0.41 → 1.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/FormContainer.vue
CHANGED
|
@@ -4,162 +4,164 @@ import {computed, defineComponent, reactive, toRef} from "vue";
|
|
|
4
4
|
import {Alert} from "vue3-bootstrap-components";
|
|
5
5
|
|
|
6
6
|
export default defineComponent({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
method: {
|
|
16
|
-
default: 'post'
|
|
17
|
-
},
|
|
18
|
-
only: {
|
|
19
|
-
type: Array,
|
|
20
|
-
default: [],
|
|
21
|
-
required: false,
|
|
22
|
-
},
|
|
23
|
-
modelValue: {
|
|
24
|
-
type: Object,
|
|
25
|
-
default: {},
|
|
26
|
-
required: false,
|
|
27
|
-
},
|
|
28
|
-
submitHandler: {
|
|
29
|
-
type: Function,
|
|
30
|
-
default: null,
|
|
31
|
-
required: false,
|
|
32
|
-
},
|
|
7
|
+
components: {Alert},
|
|
8
|
+
emits: ['submit', 'reset', 'onStart', 'onFinish', 'onSuccess', 'onError', 'change'],
|
|
9
|
+
props: {
|
|
10
|
+
url: {
|
|
11
|
+
type: String,
|
|
12
|
+
default: '',
|
|
13
|
+
required: false,
|
|
33
14
|
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
15
|
+
method: {
|
|
16
|
+
default: 'post'
|
|
17
|
+
},
|
|
18
|
+
only: {
|
|
19
|
+
type: Array,
|
|
20
|
+
default: [],
|
|
21
|
+
required: false,
|
|
22
|
+
},
|
|
23
|
+
modelValue: {
|
|
24
|
+
type: Object,
|
|
25
|
+
default: {},
|
|
26
|
+
required: false,
|
|
27
|
+
},
|
|
28
|
+
submitHandler: {
|
|
29
|
+
type: Function,
|
|
30
|
+
default: null,
|
|
31
|
+
required: false,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
setup(props) {
|
|
35
|
+
const formEl = toRef('formEl');
|
|
36
|
+
const formData = reactive(props.modelValue);
|
|
37
|
+
const form = useForm({
|
|
38
|
+
hasMessage: false,
|
|
39
|
+
successMessage: null,
|
|
40
|
+
...formData
|
|
41
|
+
});
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
form.getID = function (el) {
|
|
44
|
+
if (typeof el === String) {
|
|
45
|
+
return (formEl.value?.id ? formEl.value?.id + '-' : '') + '-' + el;
|
|
46
|
+
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
return (formEl.value?.id ? formEl.value?.id + '-' : '') + ((el.group ? el.group?.name + '-' + el.group?.groupID + '-' : '')) + el.name + (el.value ? '-' + el.value : '');
|
|
49
|
+
};
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
51
|
+
return {form, formData, formEl};
|
|
52
|
+
},
|
|
53
|
+
provide() {
|
|
54
|
+
return {
|
|
55
|
+
form: computed(() => this.form)
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
watch: {
|
|
59
|
+
form: {
|
|
60
|
+
handler: function (newVal) {
|
|
61
|
+
const {
|
|
62
|
+
isDirty,
|
|
63
|
+
errors,
|
|
64
|
+
hasErrors,
|
|
65
|
+
hasMessage,
|
|
66
|
+
successMessage,
|
|
67
|
+
processing,
|
|
68
|
+
progress,
|
|
69
|
+
wasSuccessful,
|
|
70
|
+
recentlySuccessful,
|
|
71
|
+
__rememberable,
|
|
72
|
+
...cleanedData
|
|
73
|
+
} = newVal;
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
this.$emit('change', cleanedData);
|
|
76
|
+
this.$emit('update:modelValue', cleanedData)
|
|
77
|
+
},
|
|
78
|
+
deep: true,
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
methods: {
|
|
82
|
+
reset() {
|
|
83
|
+
this.form.reset();
|
|
80
84
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.form.reset();
|
|
84
|
-
},
|
|
85
|
-
async submit(event) {
|
|
86
|
-
const formValues = this.modelValue;
|
|
87
|
-
|
|
88
|
-
if (this.submitHandler) {
|
|
89
|
-
await this.submitHandler(event);
|
|
90
|
-
} else {
|
|
91
|
-
this.$emit('submit', event);
|
|
92
|
-
await this.form.transform(function (formDataValues) {
|
|
85
|
+
async submit(event) {
|
|
86
|
+
const formValues = this.modelValue;
|
|
93
87
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
88
|
+
if (this.submitHandler) {
|
|
89
|
+
await this.submitHandler(event);
|
|
90
|
+
} else {
|
|
91
|
+
this.$emit('submit', event);
|
|
92
|
+
await this.form.transform(function (formDataValues) {
|
|
93
|
+
delete formDataValues.hasMessage;
|
|
94
|
+
delete formDataValues.successMessage;
|
|
98
95
|
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
let data = JSON.stringify({
|
|
97
|
+
...formValues,
|
|
98
|
+
...formDataValues,
|
|
99
|
+
});
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
101
|
+
const persianDigits = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g];
|
|
102
|
+
const arabicDigits = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g];
|
|
105
103
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
onStart: () => {
|
|
110
|
-
if(this.form.hasMessage){
|
|
111
|
-
this.form.hasMessage = false;
|
|
112
|
-
}
|
|
113
|
-
if(this.form.successMessage){
|
|
114
|
-
this.form.hasMessage = null;
|
|
115
|
-
}
|
|
104
|
+
for (let i = 0; i < 10; i++) {
|
|
105
|
+
data = data.replace(persianDigits[i], i).replace(arabicDigits[i], i);
|
|
106
|
+
}
|
|
116
107
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
this.reset();
|
|
108
|
+
return JSON.parse(data.toLocaleString('en-US'));
|
|
109
|
+
}).submit(this.method.toString(), this.url, {
|
|
110
|
+
only: this.only,
|
|
111
|
+
onStart: () => {
|
|
112
|
+
if (this.form.hasMessage) {
|
|
113
|
+
this.form.hasMessage = false;
|
|
114
|
+
}
|
|
115
|
+
if (this.form.successMessage) {
|
|
116
|
+
this.form.hasMessage = null;
|
|
117
|
+
}
|
|
128
118
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
119
|
+
this.$emit('onStart');
|
|
120
|
+
this.form.clearErrors();
|
|
121
|
+
},
|
|
122
|
+
onFinish: (data) => {
|
|
123
|
+
this.$emit('onFinish', data);
|
|
124
|
+
},
|
|
125
|
+
onError: (errors) => {
|
|
126
|
+
this.$emit('onError', errors);
|
|
127
|
+
},
|
|
128
|
+
onSuccess: (data) => {
|
|
129
|
+
this.reset();
|
|
133
130
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
if (data?.props?.message) {
|
|
132
|
+
this.form.hasMessage = true;
|
|
133
|
+
this.form.successMessage = data?.props?.message;
|
|
137
134
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
|
|
136
|
+
this.$emit('onSuccess', data);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
expose: ['submit', 'reset'],
|
|
141
143
|
})
|
|
142
144
|
|
|
143
145
|
</script>
|
|
144
146
|
|
|
145
147
|
<template>
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
148
|
+
<form ref="formEl"
|
|
149
|
+
:action="url"
|
|
150
|
+
:method="method"
|
|
151
|
+
@submit.prevent="submit"
|
|
152
|
+
@reset="$emit('reset')"
|
|
153
|
+
:class="{'form-processing loading': form.processing,}"
|
|
154
|
+
:novalidate="!!Object.values(form.errors).length">
|
|
155
|
+
<slot name="errors" v-if="form.hasErrors" :form="form">
|
|
156
|
+
<Alert type="danger">
|
|
157
|
+
<ul class="list-unstyled p-0 m-0 fanum">
|
|
158
|
+
<li v-for="error in form.errors">{{ error }}</li>
|
|
159
|
+
</ul>
|
|
160
|
+
</Alert>
|
|
161
|
+
</slot>
|
|
162
|
+
<slot name="message" v-if="form.hasMessage" :form="form">
|
|
163
|
+
<Alert type="success" v-html="form.successMessage" v-if="form.successMessage"></Alert>
|
|
164
|
+
</slot>
|
|
165
|
+
<slot :form="form" :submit="submit"/>
|
|
166
|
+
</form>
|
|
165
167
|
</template>
|