inertia-bootstrap-forms 1.0.40 → 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/index.d.ts CHANGED
@@ -99,7 +99,27 @@ import { DefineComponent } from 'vue';
99
99
 
100
100
  export const AmountInput: DefineComponent<{}, {}, any>;
101
101
  export const CaptchaInput: DefineComponent<{}, {}, any>;
102
- export const CheckboxButtonInput: DefineComponent<{}, {}, any>;
102
+ export const CheckboxButtonInput: DefineComponent<{
103
+ name: {
104
+ type: String,
105
+ required: true,
106
+ },
107
+ id: {
108
+ type: String,
109
+ default: '',
110
+ required: false,
111
+ },
112
+ value: {
113
+ type: String,
114
+ default: 'yes',
115
+ required: false,
116
+ },
117
+ type: {
118
+ type: String,
119
+ default: 'radio',
120
+ required: false,
121
+ },
122
+ }, {}, any>;
103
123
  export const CheckboxInput: DefineComponent<{}, {}, any>;
104
124
  export const CheckboxToggle: DefineComponent<{}, {}, any>;
105
125
  export const countryCodes: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-bootstrap-forms",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "Create bootstrap forms with inertia and twitter bootstrap",
5
5
  "main": "dist/inertia-bootstrap-forms.cjs.js",
6
6
  "module": "dist/inertia-bootstrap-forms.es.js",
@@ -4,157 +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
- components: {Alert},
8
- emits: ['submit', 'reset', 'onStart', 'onFinish', 'onSuccess', '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
- 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
- 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
- });
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
- form.getID = function (el) {
44
- if (typeof el === String) {
45
- return (formEl.value?.id ? formEl.value?.id + '-' : '') + '-' + el;
46
- }
43
+ form.getID = function (el) {
44
+ if (typeof el === String) {
45
+ return (formEl.value?.id ? formEl.value?.id + '-' : '') + '-' + el;
46
+ }
47
47
 
48
- return (formEl.value?.id ? formEl.value?.id + '-' : '') + ((el.group ? el.group?.name + '-' + el.group?.groupID + '-' : '')) + el.name + (el.value ? '-' + el.value : '');
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
- 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;
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
- this.$emit('change', cleanedData);
76
- this.$emit('update:modelValue', cleanedData)
77
- },
78
- deep: true,
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
- methods: {
82
- reset() {
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
- let data = JSON.stringify({
95
- ...formValues,
96
- ...formDataValues,
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
- const persianDigits = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g];
100
- const arabicDigits = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g];
96
+ let data = JSON.stringify({
97
+ ...formValues,
98
+ ...formDataValues,
99
+ });
101
100
 
102
- for (let i = 0; i < 10; i++) {
103
- data = data.replace(persianDigits[i], i).replace(arabicDigits[i], i);
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
- return JSON.parse(data.toLocaleString('en-US'));
107
- }).submit(this.method.toString(), this.url, {
108
- only: this.only,
109
- onStart: () => {
110
- this.form.hasMessage = false;
111
- this.form.successMessage = null;
104
+ for (let i = 0; i < 10; i++) {
105
+ data = data.replace(persianDigits[i], i).replace(arabicDigits[i], i);
106
+ }
112
107
 
113
- this.$emit('onStart');
114
- this.form.clearErrors();
115
- },
116
- onFinish: (data) => {
117
- this.$emit('onFinish', data);
118
- },
119
- onError: (errors) => {
120
- },
121
- onSuccess: (data) => {
122
- 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
+ }
123
118
 
124
- if(data?.props?.message){
125
- this.form.hasMessage = true;
126
- this.form.successMessage = data?.props?.message;
127
- }
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();
128
130
 
129
- this.$emit('onSuccess', data);
130
- }
131
- });
131
+ if (data?.props?.message) {
132
+ this.form.hasMessage = true;
133
+ this.form.successMessage = data?.props?.message;
132
134
  }
133
- }
134
- },
135
- expose: ['submit', 'reset'],
135
+
136
+ this.$emit('onSuccess', data);
137
+ }
138
+ });
139
+ }
140
+ }
141
+ },
142
+ expose: ['submit', 'reset'],
136
143
  })
137
144
 
138
145
  </script>
139
146
 
140
147
  <template>
141
- <form ref="formEl"
142
- :action="url"
143
- :method="method"
144
- @submit.prevent="submit"
145
- @reset="$emit('reset')"
146
- :class="{'form-processing loading': form.processing,}"
147
- :novalidate="!!Object.values(form.errors).length">
148
- <slot name="errors" v-if="form.hasErrors" :form="form">
149
- <Alert type="danger">
150
- <ul class="list-unstyled p-0 m-0 fanum">
151
- <li v-for="error in form.errors">{{ error }}</li>
152
- </ul>
153
- </Alert>
154
- </slot>
155
- <slot name="message" v-if="form.hasMessage" :form="form">
156
- <Alert type="success" v-html="form.successMessage" v-if="form.successMessage"></Alert>
157
- </slot>
158
- <slot :form="form" :submit="submit"/>
159
- </form>
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>
160
167
  </template>