hotwire_combobox 0.2.5 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64ee128886d148aa44b82aaeefcd88f298c393fa9097d28c9ee343df356f31de
4
- data.tar.gz: c0eb83875bc403d94e930a0ed9e2f43e17f9c77c05bd28b341d0684086aa17ae
3
+ metadata.gz: fb0eaf3c6593f518473d24ffdb931dc2519adc97c74eb4539055920c3ffd5ef9
4
+ data.tar.gz: 888c826e85dc6e77b601c89fc4a573a3f45706e51203aadc7edc14b431a50245
5
5
  SHA512:
6
- metadata.gz: 8454420c02a2fc8d894c75063286d1eb7613a9d3533030f48b607d9a95317fa262744c413529b218c5ff5166810fd8dad6e051b704cda660bfd02013b8b4721e
7
- data.tar.gz: 33713116699c659f3a0d4a6a2510ad878b59894bb2bc140becc5e7543aece05563b01da82c6e6a9f1a20336dc6b89f9120eb11845af1b2b5a01ab9034bffc67b
6
+ metadata.gz: 5c2725f7a89aff33a4fa649e37f03f363c28fab51ca930337593897068c5c60732568f8fb6b43e8c7f9cdc9309fdea9dd55298baed2774c50dc0e6041c59b989
7
+ data.tar.gz: b63c3b6031f3d74190115f5f01152085491125bc5ee0a721c3c1cb0be493993f3dec83b8132424bd471b93ff36f6b248f7f27d0abb34a3821959b6b9a2900fe7
@@ -1,5 +1,5 @@
1
1
  /*!
2
- HotwireCombobox 0.2.5
2
+ HotwireCombobox 0.3.1
3
3
  */
4
4
  import { Controller } from '@hotwired/stimulus';
5
5
 
@@ -557,6 +557,11 @@ async function get(url, options) {
557
557
  return request.perform();
558
558
  }
559
559
 
560
+ async function post(url, options) {
561
+ const request = new FetchRequest("post", url, options);
562
+ return request.perform();
563
+ }
564
+
560
565
  // Copyright (c) 2021 Marcelo Lauxen
561
566
 
562
567
  // Permission is hereby granted, free of charge, to any person obtaining
@@ -800,7 +805,7 @@ Combobox.Multiselect = Base => class extends Base {
800
805
  }
801
806
 
802
807
  async _requestChips(values) {
803
- await get(this.selectionChipSrcValue, {
808
+ await post(this.selectionChipSrcValue, {
804
809
  responseKind: "turbo-stream",
805
810
  query: {
806
811
  for_id: this.element.dataset.asyncId,
@@ -1463,7 +1468,8 @@ Combobox.Toggle = Base => class extends Base {
1463
1468
  this._isSync &&
1464
1469
  !this._isSmallViewport &&
1465
1470
  inputType != "hw:clickOutside" &&
1466
- inputType != "hw:focusOutside";
1471
+ inputType != "hw:focusOutside" &&
1472
+ inputType != "hw:asyncCloser";
1467
1473
 
1468
1474
  this._lockInSelection();
1469
1475
  this._clearInvalidQuery();
@@ -1,5 +1,5 @@
1
1
  /*!
2
- HotwireCombobox 0.2.5
2
+ HotwireCombobox 0.3.1
3
3
  */
4
4
  (function (global, factory) {
5
5
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@hotwired/stimulus')) :
@@ -561,6 +561,11 @@ HotwireCombobox 0.2.5
561
561
  return request.perform();
562
562
  }
563
563
 
564
+ async function post(url, options) {
565
+ const request = new FetchRequest("post", url, options);
566
+ return request.perform();
567
+ }
568
+
564
569
  // Copyright (c) 2021 Marcelo Lauxen
565
570
 
566
571
  // Permission is hereby granted, free of charge, to any person obtaining
@@ -804,7 +809,7 @@ HotwireCombobox 0.2.5
804
809
  }
805
810
 
806
811
  async _requestChips(values) {
807
- await get(this.selectionChipSrcValue, {
812
+ await post(this.selectionChipSrcValue, {
808
813
  responseKind: "turbo-stream",
809
814
  query: {
810
815
  for_id: this.element.dataset.asyncId,
@@ -1467,7 +1472,8 @@ HotwireCombobox 0.2.5
1467
1472
  this._isSync &&
1468
1473
  !this._isSmallViewport &&
1469
1474
  inputType != "hw:clickOutside" &&
1470
- inputType != "hw:focusOutside";
1475
+ inputType != "hw:focusOutside" &&
1476
+ inputType != "hw:asyncCloser";
1471
1477
 
1472
1478
  this._lockInSelection();
1473
1479
  this._clearInvalidQuery();
@@ -1,6 +1,6 @@
1
1
  import Combobox from "hw_combobox/models/combobox/base"
2
2
  import { cancel, nextRepaint } from "hw_combobox/helpers"
3
- import { get } from "hw_combobox/vendor/requestjs"
3
+ import { post } from "hw_combobox/vendor/requestjs"
4
4
 
5
5
  Combobox.Multiselect = Base => class extends Base {
6
6
  navigateChip(event) {
@@ -79,7 +79,7 @@ Combobox.Multiselect = Base => class extends Base {
79
79
  }
80
80
 
81
81
  async _requestChips(values) {
82
- await get(this.selectionChipSrcValue, {
82
+ await post(this.selectionChipSrcValue, {
83
83
  responseKind: "turbo-stream",
84
84
  query: {
85
85
  for_id: this.element.dataset.asyncId,
@@ -16,7 +16,8 @@ Combobox.Toggle = Base => class extends Base {
16
16
  this._isSync &&
17
17
  !this._isSmallViewport &&
18
18
  inputType != "hw:clickOutside" &&
19
- inputType != "hw:focusOutside"
19
+ inputType != "hw:focusOutside" &&
20
+ inputType != "hw:asyncCloser"
20
21
 
21
22
  this._lockInSelection()
22
23
  this._clearInvalidQuery()
@@ -46,7 +46,7 @@ module HotwireCombobox::Component::Customizable
46
46
  custom = custom_attrs[element]
47
47
 
48
48
  coalesce = ->(key, value) do
49
- if value.is_a?(String) || value.is_a?(Array)
49
+ if custom.has_key?(key) && (value.is_a?(String) || value.is_a?(Array))
50
50
  view.token_list(value, custom.delete(key))
51
51
  else
52
52
  value
@@ -16,6 +16,7 @@ class HotwireCombobox::Component
16
16
  data: {},
17
17
  dialog_label: nil,
18
18
  form: nil,
19
+ free_text: false,
19
20
  id: nil,
20
21
  input: {},
21
22
  label: nil,
@@ -26,9 +27,9 @@ class HotwireCombobox::Component
26
27
  options: [],
27
28
  value: nil,
28
29
  **rest
29
- @view, @autocomplete, @id, @name, @value, @form, @async_src, @label,
30
+ @view, @autocomplete, @id, @name, @value, @form, @async_src, @label, @free_text,
30
31
  @name_when_new, @open, @data, @mobile_at, @multiselect_chip_src, @options, @dialog_label =
31
- view, autocomplete, id, name.to_s, value, form, async_src, label,
32
+ view, autocomplete, id, name.to_s, value, form, async_src, label, free_text,
32
33
  name_when_new, open, data, mobile_at, multiselect_chip_src, options, dialog_label
33
34
 
34
35
  @combobox_attrs = input.reverse_merge(rest).deep_symbolize_keys
@@ -189,15 +190,23 @@ class HotwireCombobox::Component
189
190
 
190
191
  private
191
192
  attr_reader :view, :autocomplete, :id, :name, :value, :form,
192
- :name_when_new, :open, :data, :combobox_attrs, :mobile_at,
193
+ :free_text, :open, :data, :combobox_attrs, :mobile_at,
193
194
  :association_name, :multiselect_chip_src
194
195
 
196
+ def name_when_new
197
+ if free_text && @name_when_new.blank?
198
+ hidden_field_name
199
+ else
200
+ @name_when_new
201
+ end
202
+ end
203
+
195
204
  def name_when_new_on_multiselect_must_match_original_name
196
205
  return unless multiselect? && name_when_new.present?
197
206
 
198
- unless name_when_new.to_s == name
207
+ unless name_when_new.to_s == hidden_field_name
199
208
  errors.add :name_when_new, :must_match_original_name,
200
- message: "must match the regular name ('#{name}', in this case) on multiselect comboboxes."
209
+ message: "must match the regular name ('#{hidden_field_name}', in this case) on multiselect comboboxes."
201
210
  end
202
211
  end
203
212
 
@@ -37,7 +37,7 @@ module HotwireCombobox
37
37
  def hw_paginated_combobox_options(
38
38
  options,
39
39
  for_id: params[:for_id],
40
- src: request.fullpath,
40
+ src: hw_fullpath_for_pagination,
41
41
  next_page: nil,
42
42
  render_in: {},
43
43
  include_blank: {},
@@ -168,6 +168,11 @@ module HotwireCombobox
168
168
  end
169
169
 
170
170
  private
171
+ def hw_fullpath_for_pagination
172
+ transient_params = %w[ input_type ]
173
+ hw_uri_with_params request.path, **request.query_parameters.except(*transient_params)
174
+ end
175
+
171
176
  def hw_combobox_next_page_uri(uri, next_page, for_id)
172
177
  return unless next_page
173
178
 
@@ -1,3 +1,3 @@
1
1
  module HotwireCombobox
2
- VERSION = "0.2.5"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotwire_combobox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Farias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-04 00:00:00.000000000 Z
11
+ date: 2024-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
- rubygems_version: 3.5.9
147
+ rubygems_version: 3.5.10
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: Accessible Autocomplete for Rails apps