diff --git a/app/components/radio-button.hbs b/app/components/radio-button.hbs
new file mode 100644
index 0000000..dc6fc28
--- /dev/null
+++ b/app/components/radio-button.hbs
@@ -0,0 +1,16 @@
+
diff --git a/app/components/radio-button.js b/app/components/radio-button.js
new file mode 100644
index 0000000..ad4a363
--- /dev/null
+++ b/app/components/radio-button.js
@@ -0,0 +1,15 @@
+import Component from '@glimmer/component';
+import { action } from '@ember/object';
+
+export default class RadioButtonComponent extends Component {
+ @action
+ updateSelection(event) {
+ // Проверим, что event и event.target существуют
+ if (event && event.target) {
+ const selectedValue = event.target.value; // Получаем значение из event
+ this.args.updateValue(selectedValue); // Передаём выбранное значение
+ } else {
+ console.error('Event or event.target is undefined');
+ }
+ }
+}
diff --git a/app/components/step-bar.hbs b/app/components/step-bar.hbs
index c1a02b4..88a0f74 100644
--- a/app/components/step-bar.hbs
+++ b/app/components/step-bar.hbs
@@ -1,5 +1,5 @@
- {{this.currentStep}} of {{this.totalSteps}} Steps
+ Step {{this.args.currentStep}} of {{this.args.totalSteps}}
diff --git a/app/components/step-bar.js b/app/components/step-bar.js
index c249782..ff7fb4a 100644
--- a/app/components/step-bar.js
+++ b/app/components/step-bar.js
@@ -1,11 +1,7 @@
import Component from '@glimmer/component';
-import { tracked } from '@glimmer/tracking';
export default class StepBarComponent extends Component {
- @tracked currentStep = 1;
- @tracked totalSteps = 5;
-
get progress() {
- return (this.currentStep / this.totalSteps) * 100;
+ return (this.args.currentStep / this.args.totalSteps) * 100;
}
}
diff --git a/app/components/submit-button.js b/app/components/submit-button.js
index b9eba1c..3ee532c 100644
--- a/app/components/submit-button.js
+++ b/app/components/submit-button.js
@@ -5,7 +5,6 @@ export default class SubmitButtonComponent extends Component {
@action
handleClick() {
if (this.args.element.action === 'nextPage') {
-
this.args.onNextPage();
}
}
diff --git a/app/controllers/survey.js b/app/controllers/survey.js
index f404b78..8758ff4 100644
--- a/app/controllers/survey.js
+++ b/app/controllers/survey.js
@@ -2,25 +2,44 @@ import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
-export default class SurveyPageController extends Controller {
- @tracked name = ''; // Отслеживаемое значение имени
+class PageElement {
+ @tracked value = '';
+
+ constructor(type, label, id, required = false, options = []) {
+ this.type = type;
+ this.label = label;
+ this.id = id;
+ this.required = required;
+ this.options = options;
+ }
+}
+export default class SurveyPageController extends Controller {
@tracked currentStep = 1;
- totalSteps = 5;
+ @tracked currentPage = 0;
+ totalSteps = this.pages.length;
@tracked pages = [
{
- name: 'Introduction',
+ name: 'Overal Info',
elements: [
- { type: 'text', label: 'Enter your name', id: 'name', value: '' }
- ]
+ new PageElement('text', 'Department', 'name', true),
+ new PageElement('text', 'Role', 'role', 'name', true),
+ new PageElement('text', 'Age', 'age', 'age', true),
+ new PageElement('radio', 'Select your favorite color', 'favoriteColor', true, [
+ { label: 'Red', value: 'red' },
+ { label: 'Green', value: 'green' },
+ { label: 'Blue', value: 'blue' }
+ ])
+ ],
},
{
- name: 'Contact Information',
+ name: 'Work experience',
elements: [
- { type: 'email', label: 'Enter your email', id: 'email', value: '' }
- ]
- }
+ new PageElement('text', 'Previous company', 'prevComp', true),
+ new PageElement('text', 'Previous role', 'currRole', true),
+ ],
+ },
];
@tracked currentPage = 0;
@@ -29,12 +48,35 @@ export default class SurveyPageController extends Controller {
return this.pages[this.currentPage];
}
- // Проверка, что имя введено, чтобы активировать кнопку "Proceed"
- get isNextEnabled() {
- return this.name.trim() !== '';
+ @action
+updateElementValue(element, eventOrValue) {
+ // Если передается событие, это input или change, получаем значение
+ const value = eventOrValue.target ? eventOrValue.target.value : eventOrValue;
+ element.value = value; // Устанавливаем новое значение
+ // this.saveSurveyProgress(); // Сохраняем прогресс в localStorage
+}
+
+ get isNextDisabled() {
+ // Проверяем, что все обязательные поля заполнены
+ return this.currentPageConfig.elements.some(element => {
+ if (element.required) {
+ if (element.type === 'radio') {
+ return !element.value; // Если нет значения, возвращаем true (чтобы кнопка была disabled)
+ } else {
+ // Для текстовых полей проверяем пустые строки
+ return !element.value || element.value.trim() === ''; // Пустое поле
+ }
+ }
+ return false; // Если поле не обязательное, оно не влияет на состояние кнопки
+ });
+ }
+
+
+
+ get isBackEnabled() {
+ return this.currentPage > 0;
}
- // Обработчик для перехода на следующую страницу
@action
handleNextPage() {
if (this.currentPage < this.pages.length - 1) {
@@ -45,9 +87,11 @@ export default class SurveyPageController extends Controller {
}
}
- // Обработчик обновления значения поля имени
@action
- updateName(event) {
- this.name = event.target.value;
+ handleBackPage() {
+ if (this.currentPage > 0) {
+ this.currentPage--;
+ this.currentStep--;
+ }
}
}
diff --git a/app/templates/survey.hbs b/app/templates/survey.hbs
index 7872f7b..293d635 100644
--- a/app/templates/survey.hbs
+++ b/app/templates/survey.hbs
@@ -7,21 +7,32 @@
{{#each this.currentPageConfig.elements as |element|}}
{{#if (eq element.type "text")}}
-
+
{{/if}}
+
+ {{#if (eq element.type "radio")}}
+
+ {{/if}}
{{/each}}
+
diff --git a/tests/integration/components/radio-button-test.js b/tests/integration/components/radio-button-test.js
new file mode 100644
index 0000000..f2f8b77
--- /dev/null
+++ b/tests/integration/components/radio-button-test.js
@@ -0,0 +1,26 @@
+import { module, test } from 'qunit';
+import { setupRenderingTest } from 'survey-builder/tests/helpers';
+import { render } from '@ember/test-helpers';
+import { hbs } from 'ember-cli-htmlbars';
+
+module('Integration | Component | radio-button', function (hooks) {
+ setupRenderingTest(hooks);
+
+ test('it renders', async function (assert) {
+ // Set any properties with this.set('myProperty', 'value');
+ // Handle any actions with this.set('myAction', function(val) { ... });
+
+ await render(hbs``);
+
+ assert.dom().hasText('');
+
+ // Template block usage:
+ await render(hbs`
+
+ template block text
+
+ `);
+
+ assert.dom().hasText('template block text');
+ });
+});