frappe-ui 0.0.35 → 0.0.36

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frappe-ui",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "description": "A set of components and utilities for rapid UI development",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -3,7 +3,7 @@
3
3
  <Popover class="w-full">
4
4
  <template #target="{ open: openPopover }">
5
5
  <ComboboxInput
6
- :displayValue="(option) => option?.label"
6
+ :displayValue="displayValue"
7
7
  :class="['w-full form-input', { 'rounded-b-none': isComboBoxOpen }]"
8
8
  type="text"
9
9
  @change="
@@ -12,16 +12,24 @@
12
12
  openPopover()
13
13
  }
14
14
  "
15
- @focus="openPopover"
15
+ @focus="
16
+ () => {
17
+ openPopover()
18
+ showCombobox = true
19
+ }
20
+ "
21
+ @keydown.enter="showCombobox = false"
16
22
  autocomplete="off"
23
+ v-bind="$attrs"
17
24
  />
18
25
  </template>
19
26
  <template #body>
20
27
  <ComboboxOptions
21
28
  :class="[
22
- 'p-1.5 bg-white rounded-md shadow-md',
23
- { 'rounded-t-none': isComboBoxOpen },
29
+ 'p-1.5 bg-white rounded-md shadow-md rounded-t-none',
30
+ { hidden: !showCombobox },
24
31
  ]"
32
+ :static="true"
25
33
  >
26
34
  <ComboboxOption
27
35
  as="template"
@@ -61,8 +69,9 @@ import Popover from './Popover.vue'
61
69
 
62
70
  export default {
63
71
  name: 'Autocomplete',
64
- props: ['modelValue', 'options'],
65
- emits: ['update:modelValue'],
72
+ inheritAttrs: false,
73
+ props: ['modelValue', 'options', 'value'],
74
+ emits: ['update:modelValue', 'change'],
66
75
  components: {
67
76
  Popover,
68
77
  Combobox,
@@ -72,16 +81,20 @@ export default {
72
81
  },
73
82
  data() {
74
83
  return {
84
+ showCombobox: false,
75
85
  query: '',
76
86
  }
77
87
  },
78
88
  computed: {
89
+ valuePropPassed() {
90
+ return 'value' in this.$props && this.$props.value !== undefined
91
+ },
79
92
  selectedValue: {
80
93
  get() {
81
- return this.modelValue
94
+ return this.valuePropPassed ? this.value : this.modelValue
82
95
  },
83
96
  set(val) {
84
- this.$emit('update:modelValue', val)
97
+ this.$emit(this.valuePropPassed ? 'change' : 'update:modelValue', val)
85
98
  },
86
99
  },
87
100
  filteredOptions() {
@@ -96,5 +109,13 @@ export default {
96
109
  })
97
110
  },
98
111
  },
112
+ methods: {
113
+ displayValue(option) {
114
+ if (typeof option === 'string') {
115
+ return option
116
+ }
117
+ return option?.label
118
+ },
119
+ },
99
120
  }
100
121
  </script>
@@ -58,6 +58,10 @@ export function createResource(options, vm, getResource) {
58
58
  options.onFetch.call(vm, out.params)
59
59
  }
60
60
 
61
+ if (options.beforeSubmit) {
62
+ options.beforeSubmit.call(vm, out.params)
63
+ }
64
+
61
65
  let validateFunction = tempOptions.validate || options.validate
62
66
  let errorFunctions = [options.onError, tempOptions.onError]
63
67
  let successFunctions = [options.onSuccess, tempOptions.onSuccess]
@@ -174,11 +178,18 @@ export function createDocumentResource(options, vm) {
174
178
  fieldname: values,
175
179
  }
176
180
  },
181
+ beforeSubmit(params) {
182
+ out.previousDoc = JSON.stringify(out.doc)
183
+ Object.assign(out.doc, params.fieldname || {})
184
+ },
177
185
  onSuccess(data) {
178
186
  out.doc = transform(data)
179
187
  options.setValue?.onSuccess?.call(vm, data)
180
188
  },
181
- onError: options.setValue?.onError,
189
+ onError(error) {
190
+ out.doc = JSON.parse(out.previousDoc)
191
+ options.setValue?.onError?.call(vm, error)
192
+ },
182
193
  }
183
194
 
184
195
  let out = reactive({