decidim-forms 0.23.1.rc1 → 0.23.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: 3d243c84e3cac34d2f57549c5bf93d86f9a2e5e92a2283abe5d12c1b726d7841
4
- data.tar.gz: a628e4913fd4c127fb017acbfacef68afc3e620f1f8accecfc84c71ae2d634f2
3
+ metadata.gz: 00b6fa084292af8d4b343f801ccc5725a7983e3390b41dcd00f2b84b34afc914
4
+ data.tar.gz: 9f037814dca4fd315e6425074dc2d8c42f8c144d1bb8c5042897dd8ab5410bdf
5
5
  SHA512:
6
- metadata.gz: 41ee0e65fa6222480e067590b4f4b7ce4c1c58e1c570ea04a980f1a391e2d2e2bc8c3eea4874af7c43ccfa4da4ea222c90ea51160f3f92fdbf282e3d7775b11a
7
- data.tar.gz: d3f5d320f806492127a8ea67bd1b88aaba0921cc5f315a8d5cc093c618a0b500e70c5528a28f1b648136301ac0bf6eb2dd3b60af3630352675f83fa0c0dbc624
6
+ metadata.gz: fc48b056500a941f30b72dd044e9614008b8a0e84111e10af937ce00bab58d13a2e8938a4fa7a8dea9660dbb6c00ffc5b897330f42a9f73a2203edd5c86dd6d9
7
+ data.tar.gz: a0dbe8818ba0efbe2d7d8b1f9503c5b07cde7023437d81ab5ee1c1695a16631d26e054cc8dd072460c97c652101ef34ef5489e6bfb596cc6376d58f3e53fd184
@@ -29,14 +29,13 @@
29
29
  let multipleInput = [];
30
30
 
31
31
  $conditionWrapperField.find(".radio-button-collection, .check-box-collection").find(".collection-input").each((idx, el) => {
32
- const $label = $(el).find("label");
33
- const checked = !$label.find("input[type='hidden']").is("[disabled]");
32
+ const $input = $(el).find("input[name$=\\[body\\]]");
33
+ const checked = $input.is(":checked");
34
34
 
35
35
  if (checked) {
36
- const $textField = $(el).find("input[name$=\\[custom_body\\]]");
37
- const text = $textField.val();
38
- const value = $label.find("input:not([type='hidden'])").val();
39
- const id = $label.find("input[type='hidden']").val();
36
+ const text = $(el).find("input[name$=\\[custom_body\\]]").val();
37
+ const value = $input.val();
38
+ const id = $(el).find("input[name$=\\[answer_option_id\\]]").val();
40
39
 
41
40
  multipleInput.push({ id, value, text });
42
41
  }
@@ -51,7 +51,7 @@ module Decidim
51
51
 
52
52
  def display_conditions_fulfilled?
53
53
  question.display_conditions.all? do |condition|
54
- answer = question.questionnaire.answers.find_by(question: condition.condition_question)
54
+ answer = context.responses&.find { |r| r.question_id&.to_i == condition.condition_question.id }
55
55
  condition.fulfilled?(answer)
56
56
  end
57
57
  end
@@ -23,6 +23,11 @@ module Decidim
23
23
  end
24
24
  end
25
25
 
26
+ # Add other responses to the context so AnswerForm can validate conditional questions
27
+ def before_validation
28
+ context.responses = attributes[:responses]
29
+ end
30
+
26
31
  # Public: Splits reponses by step, keeping the separator.
27
32
  #
28
33
  # Returns an array of steps. Each step is a list of the questions in that
@@ -21,18 +21,19 @@ module Decidim
21
21
  # Answer option provided to check for "equal" or "not_equal" (optional)
22
22
  belongs_to :answer_option, class_name: "AnswerOption", foreign_key: "decidim_answer_option_id", optional: true
23
23
 
24
- def fulfilled?(answer)
24
+ def fulfilled?(answer_form)
25
+ return answer_form.present? if condition_type == "answered"
26
+ return answer_form.blank? if condition_type == "not_answered"
27
+ # rest of options require presence
28
+ return if answer_form.blank?
29
+
25
30
  case condition_type
26
- when "answered"
27
- answer.present?
28
- when "not_answered"
29
- answer.blank?
30
31
  when "equal"
31
- answer.present? ? answer.choices.pluck(:decidim_answer_option_id).include?(answer_option.id) : false
32
+ answer_form.choices.pluck(:answer_option_id).include?(answer_option.id)
32
33
  when "not_equal"
33
- answer.present? ? !answer.choices.pluck(:decidim_answer_option_id).include?(answer_option.id) : true
34
+ answer_form.choices.pluck(:answer_option_id).exclude?(answer_option.id)
34
35
  when "match"
35
- answer.present? ? condition_value.values.any? { |value| answer.body.match?(Regexp.new(value, Regexp::IGNORECASE)) } : false
36
+ condition_value.values.reject(&:blank?).any? { |value| answer_form_matches?(answer_form, value) }
36
37
  end
37
38
  end
38
39
 
@@ -46,6 +47,19 @@ module Decidim
46
47
  value: condition_value&.dig(I18n.locale.to_s)
47
48
  }.compact
48
49
  end
50
+
51
+ private
52
+
53
+ def answer_form_matches?(answer_form, value)
54
+ search = Regexp.new(value, Regexp::IGNORECASE)
55
+ if answer_form.body
56
+ answer_form.body.match?(search)
57
+ else
58
+ answer_form.choices.any? do |choice_value|
59
+ choice_value.body&.match?(search) || choice_value.custom_body&.match?(search)
60
+ end
61
+ end
62
+ end
49
63
  end
50
64
  end
51
65
  end
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-forms version.
5
5
  module Forms
6
6
  def self.version
7
- "0.23.1.rc1"
7
+ "0.23.1"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.1.rc1
4
+ version: 0.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-11-06 00:00:00.000000000 Z
14
+ date: 2020-11-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: decidim-core
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.23.1.rc1
22
+ version: 0.23.1
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.23.1.rc1
29
+ version: 0.23.1
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: wicked_pdf
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -61,28 +61,28 @@ dependencies:
61
61
  requirements:
62
62
  - - '='
63
63
  - !ruby/object:Gem::Version
64
- version: 0.23.1.rc1
64
+ version: 0.23.1
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - '='
70
70
  - !ruby/object:Gem::Version
71
- version: 0.23.1.rc1
71
+ version: 0.23.1
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: decidim-dev
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - '='
77
77
  - !ruby/object:Gem::Version
78
- version: 0.23.1.rc1
78
+ version: 0.23.1
79
79
  type: :development
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - '='
84
84
  - !ruby/object:Gem::Version
85
- version: 0.23.1.rc1
85
+ version: 0.23.1
86
86
  description: A forms gem for decidim.
87
87
  email:
88
88
  - josepjaume@gmail.com
@@ -296,9 +296,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
296
296
  version: '2.6'
297
297
  required_rubygems_version: !ruby/object:Gem::Requirement
298
298
  requirements:
299
- - - ">"
299
+ - - ">="
300
300
  - !ruby/object:Gem::Version
301
- version: 1.3.1
301
+ version: '0'
302
302
  requirements: []
303
303
  rubygems_version: 3.0.3
304
304
  signing_key: