inertia-bootstrap-forms 1.2.4 → 2.1.2

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