How to render input inside label - using zend form - zend-framework

As title says, how can i generate a form using zend form having input inside label?
Something like
<label class="checkbox" for="persistent">
<input type="checkbox" value="" id="persistent" data-toggle="checkbox">
Remember Me
</label>
Thanks!

You can likely add a decorator to your input field.

Related

Wicket: access field from inner form

I have a Wicket page with this structure:
<form wicket:id="generalForm" method="post" class="form_recherche">
<input value="" type="text" wicket:id="myField_1" />
<form wicket:id="innerForm" method="post">
<input value="" type="text" wicket:id="myField_2"/>
<input type="submit" class="button-classic" wicket:id="accept_2"/>
</form>
<input type="submit" class="button-classic" wicket:id="accept_1" />
</form>
1 external form with 1 inner form. One field each. The fact is that when the "accept_2" button is clicked, the field "myField_1" is not submitted to the server (only the "myField_2" is submitted). And in fact, I would need the "field_1" field to do some validation.
What am I missing and why isn't the "myField_1" being filled on the server why "accept_2" is clicked?
You need to override Form#wantSubmitOnNestedFormSubmit() on the outer Form to return true. This way you will tell Wicket that you want the (outer) form to be submitted as well when one of its nested forms is submitted.
You used SO tags wicket-1.5 and wicket-1.6. I am not sure whether this method is available for your version of Wicket.

angular form disable submit button if field is empty

Sounds so simple but I've tried quite a few things and none work.
I'm using Angular 4 and my form is template-driven:
<form #form="ngForm" novalidate>
<label for="insz">{{ 'SEARCH_PAGE.searchInszNumber' | translate }}</label>
<input type="text" name="insz" [placeholder]="'SEARCH_PAGE.searchInszNumber' | translate" #input required>
<button (click)="onSearch(input.value)" ><span>{{'SEARCH_PAGE.search' | translate }}</span></button>
</form>
I want to disable the button when the (one and only) input field is empty.
You are missing ngModel in your input, for your input field to actually be a form control:
<input type="text" name="insz" ngModel
[placeholder]="'SEARCH_PAGE.searchInszNumber' | translate" #input required>
and then you need to disable the button of course if form is not valid:
<button [disabled]="!form.valid" (click)="onSearch(input.value)" >Submit</button>
You could take a look at reactive forms. I had no knowledge of them until a week ago, but they're so powerful !
This means all you need to do is add a Validator (Validators.required in your case), and add a disabled condition to your button. And that's it, you're set.

Zend Form text element with array notation issue

I'm using Zend_Form and have got stuck in a situation. I have an array of some values like below :
$feeTypes = array(1,2,3,4);
and want to create 6 text elements in zend form that should be rendered like following:
<input type="text" name="class_fee_type[1]" />
<input type="text" name="class_fee_type[2]" />
<input type="text" name="class_fee_type[3]" />
<input type="text" name="class_fee_type[4]" />
I tried the following code but don't know that how to associate the above $feeType array.
$class_fee_type = $this->CreateElement('text','class_fee_type')
->setRequired(false)
->setAllowEmpty(false)
->setIsArray(true)
->setRegisterInArrayValidator(false)
->setDecorators(array( array('ViewHelper')
));
I'm not using any subform in this form. This is absolutely simple zend form.
Thanks.
I'm talking from ZF1 point of view:
It seems like there is no standard way of doing what you need. So I would recommend write your own form element and element view helper for that. And passing your indexes array as options to element.
Note: to use setRegisterInArrayValidator - your Zend form element should extend Zend_Form_Element_Multi.

AngularJS form inputs: how to set default values based on $scope but bind to new form model

Building a CMS with node, mongoDB & angularjs. I have an edit form with inputs that I want to bind to the $scope so their values are populated with existing data. Ex:
<form ng-submit="editArticle(article._id, article)" class="edit-form">
<label for="hed">Hed: <input type="text" name="hed" ng-model="article.hed" value="{{article.hed}}" /></label>
<label for="dek">Dek: <input type="text" name="dek" ng-model="article.dek" placeholder="{{article.dek}}" /></label>
<input type="submit" value="Save Changes"></input>
</form>
This appropriately fills in the input values with the current data from my mongo database. However, I would like to bind to a new form scope, so it doesn't try to pass in every value in the article scope, just the new scope within the form. (Article scope currently consists of every field in the article document in Mongo. If I pass all of this data in, I get an error about invalid schema because it is trying to pass in the __v field as well.)
So ideally I want to do this:
<form ng-submit="editArticle(article._id, form)" class="edit-form">
<label for="hed">Hed: <input type="text" name="hed" ng-model="form.hed" value="{{article.hed}}" /></label>
<label for="dek">Dek: <input type="text" name="dek" ng-model="form.dek" placeholder="{{article.dek}}" /></label>
<input type="submit" value="Save Changes"></input>
</form>
So on submit, it only passes form.hed and form.dek to my database. However, now these input fields are blank because they're not bound to the original article data. The user would have to re-fill in each of the fields with the original values. Is there a way to bind to multiple models orrrr bind to a current model, but on submit only send the updated form data?
EDIT:
It looks like I have to add the ng-change attribute to each field, to populate the input fields with the original scope, then on change, set the form scope equal to the changed value. Eg.
<form ng-submit="editArticle(article._id, form)" class="edit-form">
<label for="hed">Hed: <input type="text" name="hed" ng-change(form.article = article.hed) ng-model="article.hed" /></label>
<label for="dek">Dek: <input type="text" name="dek" ng-change(form.dek = article.dek) ng-model="article.dek" placeholder="{{article.dek}}" /></label>
<input type="submit" value="Save Changes"></input>
</form>
Not sure how thrilled I am about this solution, but it works. If anyone knows a more efficient way to accomplish this please let me know!
Do a copy of the original object (or part of it) upon receiving it from DB and bind your from to it.
Coping objects before edit is a very good pattern since it allows you to easily provide additional functionality like revert edits and disable save buttons if no edit was made.

Do I really have to remove a second, hidden form field from within a label for my HTML to validate?

We have the following code in which we are getting errors in the w3c validator for "Any input descendant of a label element with a for attribute must have an ID value that matches that for attribute." and "The label element may contain at most one input, button, select, textarea, or keygen descendant." Is this something that should just be ignored by the validator (as it is seeminlgly correct) or should it be changed to appease the w3c? Note this is html5 doctype.
<fieldset>
<label for="user_is_subscribed">
<input type="hidden" value="0" name="user[is_subscribed]">
<input type="checkbox" value="1" name="user[is_subscribed]" id="user_is_subscribed">
Newsletter Signup
</label>
<span class="checkLabel">We will never spam or give away your information</span>
</fieldset>
Thank in advance!
Labels should contain at most one input element. Move the hidden input out of the label. Also, when an input is a descendant of a label, the for attribute is superfluous.
<fieldset>
<input type="hidden" value="0" name="user[is_subscribed]">
<label>
<input type="checkbox" value="1" name="user[is_subscribed]" id="user_is_subscribed">
Newsletter Signup
</label>
<span class="checkLabel">We will never spam or give away your information</span>
</fieldset>
Is this something that should just be ignored by the validator
No
(as it is seeminlgly correct)
It isn't
or should it be changed
Yes
to appease the w3c?
No. It should be changed because it is wrong, and browsers have to error correct to figure out which element the label is associated with.
The label isn't labeling the hidden input, move it elsewhere.