I'm working on an Angular2 project & currently i'm stuck with a Quizz module, so illustrating the problem ; when a candidate wants to pass a test he will get that test with some questions ; every question has 4 propositions with radio buttons and he should answer merely by checking one of them for every question. here is the HTML snippet of what i'm talking about :
<div *ngFor="#qt of listQuestion">
<h3 class="uk-accordion-title" >{{qt.wordingQ}}</h3>
<div class="uk-accordion-content">
<input type="radio" id="radio_demo_1" />
<label for="radio_demo_1"> <b>{{qt.lpo[0]}}</b></label> <br><br>
<input type="radio" id="radio_demo_2" />
<label for="radio_demo_2"><b>{{qt.lpo[1]}}</b></label><br><br>
<input type="radio" id="radio_demo_3" />
<label for="radio_demo_3"> <b>{{qt.lpo[2]}}</b></label> <br><br>
<input type="radio" id="radio_demo_4" />
<label for="radio_demo_4"><b>{{qt.lpo[3]}}</b></label>
</div> </div>
Where the listQuestion is a list of Question entities which each one of them has a wording and a list of propositions (lpo), in that way i cannot check only one radio button for every question as it is shown below :
I tried to remove the id in the <input> tags and it still the same problem , I've changed the id by name and give the same name for all tags thus, I could check only one proposition but when moving to another question and checking a new proposition , the first one will be cleared.
Any help Please ?
Your problem is that the way you currently do it, you have a single radio group for all questions. You can solve it by creating radio element name attributes dynamically. Something like this:
<h3 class="uk-accordion-title" >{{qt.id}}</h3>
<input type="radio" id="radio_demo_{{qt.id}}_{{index$}}" name="radio_demo_{{qt.id}}_{{index$}}" />
<label for="radio_demo_{{qt.id}}_{{index$}}"> <b>{{qt.lpo[0]}}</b></label> <br><br>
{{qt.id}} (or any other qt property that uniquely identifies the question) is the key here.
This way, you'll have a separate radio group for each question, because group names won't intersect.
Related
I'm trying to add objects to a Firebase database and to retrieve the name and value from two text boxes.
<label class="item item-input">
<span class="input-label">Beer Name</span>
<input type="text" id='nomeBirra'>
</label>
<label class="item item-input">
<span class="input-label">Review</span>
<textarea name="comment" placeholder="Enter review" id="Recensione"></textarea>
</label>
This retrieves the two text areas:
var nameBirra=document.getElementById("nomeBirra")
var valueBirra=document.getElementById("Recensione")
This is the piece of code that adds a new object to database
rootRef.child("databaseBirre").set({
name: nameBirra,
value: valueBirra
})
The problem is that it works, but the two parameters appear empty in the database. How can I retrieve the values inside the text boxes? Or am I doing something else wrong?
The firebase syntax is right, which is why it's appearing in the database - it's the other bit that is wrong. There are a few things that could be wrong but it's hard to say without seeing the context (e.g. are those getElementByIds wrapped in a function etc?) but the most obvious one is that you need to get the VALUE of the input box, not the box itself. So, first thing to try:
var nameBirra=document.getElementById("nomeBirra").value
etc
I'm trying to validate a form that is dynamically generated with JSON data, that is rendered to the page using ng-repeat. The data is questions with corresponding answers. The issue I'm running in to is that with a dynamic ng-model on each group, like so:
<div class="well question-well" ng-repeat="question in Posttest1Questions">
<p><strong>{{question.question}}</strong></p>
<ul>
<li ng-repeat="answers in question.answers">
<input type="radio" name="Q{{question.id}}" ng-model="question_[question.id]" id="{{question.id}}" value="{{answers.id}}" required data-key="{{answers.isCorrect}}">{{answers.answer}}
</li>
</ul>
</div>
Even when all the questions are answered, the form never turns valid. In turn, if I remove the ng-model attr, the form is always valid, even if no radio buttons has been selected.
Example Plunkr: http://plnkr.co/edit/DvcJ8byS0yF7iLp37Ets?p=preview
You can use ng-required to set a condition on the input's required status. In this case, if the model used with ng-model is null, then required. Otherwise, not required.
This way, once you've selected one of the answers (the model has a value), all of the answers for this question will not be marked as required.
<input type="radio" name="Q{{question.id}}" ng-model="question[question.id]" id="{{question.id}}" value="{{answers.id}}" ng-required="question[question.id] == null" data-key="{{answers.isCorrect}}" />
See it working here.
The underscore in
ng-model="question_[question.id]" seems wrong to me.
Please try ng-model="question[question.id]" then you can simply say required
updated your plnkr: http://plnkr.co/edit/gCZHFqd07880Os8FcxhG?p=preview
This may seem obvious to some of you, but I really am struggling to find a straight answer. I've generally googled, as well as read both the CakePHP manual and the API for an answer to the following question:
When creating an input, the following code creates the following outputs:
// in the view
echo $this->Form->input('notes');
// resultant html
<div class="input textarea">
<label for="notes">Notes</label>
<textarea id="notes" rows="5" name="notes"></textarea>
</div>
Note: this is consistent across most input types; and because it's consistent it's great for formatting.
However, with a checkbox:
//In the view
echo $this->Form->input('ticket_required',
['type' => 'checkbox']
);
// resultant HTML
<div class="input checkbox">
<input type="hidden" value="0" name="ticket_required">
<label for="ticket-required">
<input id="ticket-required" type="checkbox" value="1" name="ticket_required">
Ticket Required</label>
</div>
[Note: I understand the need/desire for the hidden field]
Now.. surely it can't be an uncommon requirement to simply want the same format approach as every other standard input?
My question - how do I make CakePHP create a checkbox element as follows:
// desired HTML
<div class="input checkbox">
<input type="hidden" value="0" name="ticket_required">
<label for="ticket-required">
Ticket Required</label>
<input id="ticket-required" type="checkbox" value="1" name="ticket_required">
</div>
To be clear: the order of visible elements is the same as other generated elements (label before input, and all encased in the wrapping div).
Please note.. i have tried the 'nestedInput' => false option. This actually gets rid of the checkbox input entirely from the div.
I can't understand why this isn't done that way... but even if it was, I can't fathom why this isn't an obvious question for the documentation.
Oh well.. hopefully someone can help me here.
Thanks in advance.
Rick
I would have thought the nestedInput would work but even if it did, you don't want to add that to every input you create throughout the website.
CakePHP 3 uses string templates to build form controls. You can modify them to suit your needs.
By default the checkbox is using the nestingLabel template so if you want to stop all inputs from being nested you can change the template.
// src/View/AppView.php
$this->loadView('Form', [
templates => [
'nestingLabel' => '<label{{attrs}}>{{text}}</label>{{hidden}}{{input}}'
],
// [More helper default config overrides][2]..
])
For more control over your helpers you can create your own that extends one of the core helpers.
How can I mimic the tags box behaviour from SO in AngularJS? I'm trying to do something kind of similar where the user enters a set of space/comma-delimited words and as each one is typed I want to parse it out and put it into an array. I know there are probably 30 different ways to do this with bespoke javascript but I'm looking to leverage AngularJS in the most efficient way possible here.
At the moment I have an ng-model based on the input field and I'm doing an ng-repeat to create spans containing each tag, but angular uses commas as the delimiter and it also includes partially-formed words. So I only want to include words that have been delimited by the space/comma and I want to put them into an array so I can perform some validation on each one as it's entered, see below.
<form role="form" class="form-inline" data-ng-submit="updateScore()">
<input data-ng-list data-ng-model="labels" placeholder="Enter labels" class="form-control" type="text" >
</form>
<span data-ng-repeat="label in labels track by $index">
<span class="badge">
{{ label }} 5 <span class="glyphicon glyphicon-remove-sign"></span>
</span>
</span>
Any ideas?
Figured it out actually...
<input data-ng-list="/[,\s]/" data-ng-model="labels" placeholder="Enter labels" class="form-control" type="text" >
I am trying to get a group of checkboxes by the name attribute. For example, I have the following:
<input name="labs[]" type="checkbox" value="lab1" />
<input name="labs[]" type="checkbox" value="lab2" />
<input name="labs[]" type="checkbox" value="lab3" />
<input name="labs[]" type="checkbox" value="lab4" />
And Im trying to get that group by doing something like:
Ext.query('input[name=labs[]]');
But that clearly doesn't work because of the square brackets that are part of the name. I'm lost as to how to do this?
You could do a "starts with" match instead:
Ext.query('input[name^=labs]');
This will not work very well if you have other elements that start with "labs" though, so you may want to add another identifier to your "labs[]" name, i.e. "labs-check[]".
Try matching an input element that has a name attribute that starts with 'labs':
Ext.query("input[name^=labs]");