-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
51 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
<div class="form-group"> | ||
<label>{{this.args.element.label}}</label> | ||
{{#each this.args.element.options as |option|}} | ||
<div class="radio-option"> | ||
<div class="field"> | ||
{{#each @element.options as |option|}} | ||
<div class="control"> | ||
<label class="radio"> | ||
<input | ||
type="radio" | ||
name={{@element.id}} | ||
value={{option.value}} | ||
checked={{eq @element.value option.value}} | ||
{{on "change" this.updateSelection}} | ||
> | ||
{{option.label}} | ||
</label> | ||
</div> | ||
{{/each}} | ||
|
||
{{#if this.showOtherInput}} | ||
<div class="control mt-2"> | ||
<input | ||
type="radio" | ||
id={{option.value}} | ||
name={{this.args.element.id}} | ||
value={{option.value}} | ||
{{on "change" this.updateSelection}} | ||
checked={{eq this.args.element.value option.value}} | ||
type="text" | ||
class="input" | ||
placeholder="Please specify" | ||
{{on "input" this.updateOtherValue}} | ||
> | ||
<label for={{option.value}}>{{option.label}}</label> | ||
</div> | ||
{{/each}} | ||
{{/if}} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,30 @@ | ||
import Component from '@glimmer/component'; | ||
import { action } from '@ember/object'; | ||
import { tracked } from '@glimmer/tracking'; | ||
|
||
export default class RadioButtonComponent extends Component { | ||
@tracked showOtherInput = false; | ||
|
||
@action | ||
updateSelection(event) { | ||
// Проверим, что event и event.target существуют | ||
if (event && event.target) { | ||
const selectedValue = event.target.value; // Получаем значение из event | ||
this.args.updateValue(selectedValue); // Передаём выбранное значение | ||
const selectedValue = event.target.value; | ||
|
||
if (selectedValue === 'other') { | ||
this.showOtherInput = true; // Показываем текстовое поле | ||
} else { | ||
console.error('Event or event.target is undefined'); | ||
this.showOtherInput = false; // Скрываем текстовое поле | ||
} | ||
|
||
if (this.args.updateValue) { | ||
this.args.updateValue(selectedValue); // Обновляем выбранное значение | ||
} | ||
} | ||
|
||
@action | ||
updateOtherValue(event) { | ||
const otherValue = event.target.value; | ||
if (this.args.updateValue) { | ||
this.args.updateValue(otherValue); // Передаем значение "Other" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters