chartManD commited on
Commit
2e940ea
·
1 Parent(s): c5675ea

Se sustituye input tipo numero por radios para tamaño de escala

Browse files
tecnicas/forms/sesion_basic_form.py CHANGED
@@ -5,6 +5,9 @@ from ..models import EstiloPalabra
5
 
6
 
7
  class SesionBasicForm(forms.Form):
 
 
 
8
  id_tecnica = forms.IntegerField(widget=forms.HiddenInput())
9
 
10
  nombre_sesion = forms.CharField(max_length=255, widget=forms.TextInput(attrs={
@@ -28,10 +31,6 @@ class SesionBasicForm(forms.Form):
28
  "placeholder": "Solo números"
29
  }), required=True)
30
 
31
- tamano_escala = forms.IntegerField(widget=forms.NumberInput(attrs={
32
- "class": "bg-surface-ligt p-1 border-b-1 text-center w-full",
33
- }), required=True, min_value=5)
34
-
35
  instrucciones = forms.CharField(max_length=255, widget=forms.TextInput(attrs={
36
  "class": "bg-surface-ligt border-b-1 text-center w-full p-1",
37
  "placeholder": "Este campo es opcional"
@@ -41,23 +40,23 @@ class SesionBasicForm(forms.Form):
41
  super().__init__(*args, **kwargs)
42
 
43
  self.fields['estilo_palabras'] = forms.ModelChoiceField(queryset=EstiloPalabra.objects.all(), widget=forms.RadioSelect(attrs={
44
- "class": "uppercase text-lg tracking-wider font-medium p-2 px-4 active:px-5 transition-all rounded-xl bg-blue-500 text-white",
45
  }), required=True, initial=EstiloPalabra.objects.first())
46
 
47
  self.fields['tipo_escala'] = forms.ModelChoiceField(queryset=TipoEscala.objects.all(), widget=forms.RadioSelect(attrs={
48
  "class": "uppercase text-lg tracking-wider font-medium p-2 px-4 active:px-5 transition-all rounded-xl bg-blue-500 text-white",
49
  }), required=True, initial=TipoEscala.objects.first())
50
 
 
 
 
 
51
  if id_tecnica_new != 0:
52
  self.fields['id_tecnica'] = forms.IntegerField(
53
  initial=id_tecnica_new, widget=forms.HiddenInput())
54
 
55
  def clean(self):
56
  data_clean = super().clean()
57
-
58
- sizes_estruturada = [5, 7, 9]
59
- sizes_continua = [9, 12, 15]
60
-
61
  escala = data_clean.get("tipo_escala")
62
 
63
  if escala and not isinstance(escala, TipoEscala):
@@ -70,9 +69,9 @@ class SesionBasicForm(forms.Form):
70
 
71
  tamano_escala = data_clean.get("tamano_escala")
72
 
73
- if escala.nombre_escala == "estructurada" and not sizes_estruturada.__contains__(tamano_escala):
74
  self.add_error("tamano_escala", "El tamaño de la escala no aplica")
75
- elif escala.nombre_escala == "continua" and not sizes_continua.__contains__(tamano_escala):
76
  self.add_error("tamano_escala", "El tamaño de la escala no aplica")
77
 
78
  id_tecnica = data_clean.get("id_tecnica")
 
5
 
6
 
7
  class SesionBasicForm(forms.Form):
8
+ sizes_structure = [5, 7, 9]
9
+ sizes_continue = [9, 13, 15]
10
+
11
  id_tecnica = forms.IntegerField(widget=forms.HiddenInput())
12
 
13
  nombre_sesion = forms.CharField(max_length=255, widget=forms.TextInput(attrs={
 
31
  "placeholder": "Solo números"
32
  }), required=True)
33
 
 
 
 
 
34
  instrucciones = forms.CharField(max_length=255, widget=forms.TextInput(attrs={
35
  "class": "bg-surface-ligt border-b-1 text-center w-full p-1",
36
  "placeholder": "Este campo es opcional"
 
40
  super().__init__(*args, **kwargs)
41
 
42
  self.fields['estilo_palabras'] = forms.ModelChoiceField(queryset=EstiloPalabra.objects.all(), widget=forms.RadioSelect(attrs={
43
+ "class": "uppercase text-lg tracking-wider font-medium p-2 px-4 active:px-5 transition-all rounded-xl bg-blue-500 text-white",
44
  }), required=True, initial=EstiloPalabra.objects.first())
45
 
46
  self.fields['tipo_escala'] = forms.ModelChoiceField(queryset=TipoEscala.objects.all(), widget=forms.RadioSelect(attrs={
47
  "class": "uppercase text-lg tracking-wider font-medium p-2 px-4 active:px-5 transition-all rounded-xl bg-blue-500 text-white",
48
  }), required=True, initial=TipoEscala.objects.first())
49
 
50
+ self.fields['tamano_escala'] = forms.IntegerField(widget=forms.HiddenInput(attrs={
51
+ "class": "cts-size-input",
52
+ }), required=True, min_value=5)
53
+
54
  if id_tecnica_new != 0:
55
  self.fields['id_tecnica'] = forms.IntegerField(
56
  initial=id_tecnica_new, widget=forms.HiddenInput())
57
 
58
  def clean(self):
59
  data_clean = super().clean()
 
 
 
 
60
  escala = data_clean.get("tipo_escala")
61
 
62
  if escala and not isinstance(escala, TipoEscala):
 
69
 
70
  tamano_escala = data_clean.get("tamano_escala")
71
 
72
+ if escala.nombre_escala == "estructurada" and not self.sizes_structure.__contains__(tamano_escala):
73
  self.add_error("tamano_escala", "El tamaño de la escala no aplica")
74
+ elif escala.nombre_escala == "continua" and not self.sizes_continue.__contains__(tamano_escala):
75
  self.add_error("tamano_escala", "El tamaño de la escala no aplica")
76
 
77
  id_tecnica = data_clean.get("id_tecnica")
tecnicas/static/js/panel-basic.js CHANGED
@@ -1,6 +1,6 @@
1
  const descriptons = {
2
- estructurada: ["Establece número de segmentos:", "Puede ser 5, 7 o 9"],
3
- continua: ["Establece la longitud de la escala:", "Puede ser 9, 12 o 15"],
4
  atributos:
5
  "Con el estilo atributos elijes las palabras para evaluar los productos",
6
  vocabulario:
@@ -12,6 +12,11 @@ let inputTamano;
12
 
13
  let inputsStyle;
14
  let helpStyle;
 
 
 
 
 
15
 
16
  initPanel();
17
 
@@ -22,6 +27,7 @@ function initPanel() {
22
  function initRadios() {
23
  inputsScale = document.getElementsByName("tipo_escala");
24
  inputTamano = document.getElementsByName("tamano_escala").item(0);
 
25
 
26
  for (let index = 0; index < inputsScale.length; index++) {
27
  let parent = inputsScale.item(index).parentElement;
@@ -46,6 +52,73 @@ function initRadios() {
46
  showDescriptionStyle(parent);
47
  }
48
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  }
50
 
51
  function showDescriptionStyle(label) {
@@ -56,6 +129,5 @@ function showDescriptionStyle(label) {
56
  function showDescriptionTamanoScale(label) {
57
  const text = label.textContent.trim();
58
  let parent = inputTamano.parentElement;
59
- parent.getElementsByTagName("p")[0].textContent = descriptons[text][0];
60
- inputTamano.placeholder = descriptons[text][1];
61
  }
 
1
  const descriptons = {
2
+ estructurada: "Establece número de segmentos:",
3
+ continua: "Establece la longitud de la escala:",
4
  atributos:
5
  "Con el estilo atributos elijes las palabras para evaluar los productos",
6
  vocabulario:
 
12
 
13
  let inputsStyle;
14
  let helpStyle;
15
+ let sizeOptionsContainer;
16
+ const SIZE_OPTIONS = {
17
+ estructurada: [5, 7, 9],
18
+ continua: [9, 13, 15],
19
+ };
20
 
21
  initPanel();
22
 
 
27
  function initRadios() {
28
  inputsScale = document.getElementsByName("tipo_escala");
29
  inputTamano = document.getElementsByName("tamano_escala").item(0);
30
+ sizeOptionsContainer = document.getElementsByClassName("cts-options-size-scale")[0];
31
 
32
  for (let index = 0; index < inputsScale.length; index++) {
33
  let parent = inputsScale.item(index).parentElement;
 
52
  showDescriptionStyle(parent);
53
  }
54
  }
55
+
56
+ initSizeOptions();
57
+ }
58
+
59
+ function initSizeOptions() {
60
+ for (let i = 0; i < inputsScale.length; i++) {
61
+ const radio = inputsScale.item(i);
62
+ radio.addEventListener('change', () => {
63
+ const tag = getTagFromLabel(radio);
64
+ populateSizeOptions(tag);
65
+ });
66
+ if (radio.checked) {
67
+ const tag = getTagFromLabel(radio);
68
+ populateSizeOptions(tag);
69
+ }
70
+ }
71
+
72
+ const form = document.querySelector('form');
73
+ if (!form) return;
74
+
75
+ form.addEventListener('submit', (e) => {
76
+ const chosen = document.querySelector('input[name="option_size_scale"]:checked');
77
+ if (chosen && inputTamano) {
78
+ inputTamano.value = chosen.value;
79
+ }
80
+
81
+ if (sizeOptionsContainer) {
82
+ const toRemove = sizeOptionsContainer.querySelectorAll('input[name="option_size_scale"]');
83
+ toRemove.forEach((el) => el.remove());
84
+ }
85
+ });
86
+ }
87
+
88
+ function getTagFromLabel(radio) {
89
+ try {
90
+ const parent = radio.parentElement;
91
+ if (!parent) return '';
92
+ const text = parent.textContent || '';
93
+ return text.trim().split(/\s+/)[0].toLowerCase();
94
+ } catch (err) {
95
+ return '';
96
+ }
97
+ }
98
+
99
+ function populateSizeOptions(tag) {
100
+ const options = SIZE_OPTIONS[tag] || SIZE_OPTIONS['estructurada'];
101
+ if (!sizeOptionsContainer) return;
102
+ sizeOptionsContainer.innerHTML = '';
103
+
104
+ options.forEach((val) => {
105
+ const label = document.createElement('label');
106
+ label.className = 'flex flex-col items-center cursor-pointer';
107
+
108
+ const input = document.createElement('input');
109
+ input.type = 'radio';
110
+ input.name = 'option_size_scale';
111
+ input.value = String(val);
112
+ input.className = 'radio radio-lg checked:bg-pink-500';
113
+
114
+ const span = document.createElement('span');
115
+ span.className = 'mt-2 text-xl text-gray-700 font-medium';
116
+ span.textContent = String(val);
117
+
118
+ label.appendChild(input);
119
+ label.appendChild(span);
120
+ sizeOptionsContainer.appendChild(label);
121
+ });
122
  }
123
 
124
  function showDescriptionStyle(label) {
 
129
  function showDescriptionTamanoScale(label) {
130
  const text = label.textContent.trim();
131
  let parent = inputTamano.parentElement;
132
+ parent.getElementsByTagName("p")[0].textContent = descriptons[text];
 
133
  }
tecnicas/templates/tecnicas/create_sesion/configuracion-panel-basic.html CHANGED
@@ -93,6 +93,20 @@
93
  <p>Establece número de segmentos:</p>
94
  {{ form_sesion.tamano_escala }}
95
  </label>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  {% if form_sesion.tamano_escala.errors %}
97
  <article
98
  class="w-fit rounded px-2 py-0.5 text-center text-white text-sm font-medium tracking-wide bg-red-500">
 
93
  <p>Establece número de segmentos:</p>
94
  {{ form_sesion.tamano_escala }}
95
  </label>
96
+ <div class="flex justify-around max-sm:flex-col gap-8 cts-options-size-scale">
97
+ <label class="flex flex-col items-center cursor-pointer">
98
+ <input type="radio" name="option_size_scale" value="5" class="radio radio-lg checked:bg-pink-500" />
99
+ <span class="mt-2 text-xl text-gray-700 font-medium">5</span>
100
+ </label>
101
+ <label class="flex flex-col items-center cursor-pointer">
102
+ <input type="radio" name="option_size_scale" value="7" class="radio radio-lg checked:bg-pink-500" />
103
+ <span class="mt-2 text-xl text-gray-700 font-medium">7</span>
104
+ </label>
105
+ <label class="flex flex-col items-center cursor-pointer">
106
+ <input type="radio" name="option_size_scale" value="9" class="radio radio-lg checked:bg-pink-500" />
107
+ <span class="mt-2 text-xl text-gray-700 font-medium">9</span>
108
+ </label>
109
+ </div>
110
  {% if form_sesion.tamano_escala.errors %}
111
  <article
112
  class="w-fit rounded px-2 py-0.5 text-center text-white text-sm font-medium tracking-wide bg-red-500">