need a tutorial about how to create custom HTML markup (like form decorators on Zend 1).
I want to generate something like:
<ul>
<li>
<label class="required"><span>*</span> Username</label>
<input id="username" name="username" type="text">
</li>
<li>
<label class="required"><span>*</span> Password</label>
<input id="password" name="password" type="password">
</li>
</ul>
Assuming the form elements are named username and password, here's an example that would give the desired output
<?php
// attributes to apply to label(s)
$labelAttr = array('class' => 'required');
// extra label content (assumes Username and Password are already present in the given elements)
$labelSpan = '<span>*</span> ';
// set the label attributes
$form->get('username')->setLabelAttributes($labelAttr);
$form->get('password')->setLabelAttributes($labelAttr);
?>
<ul>
<li>
// use the formLabel helper, hand it the extra label content, and tell it to place the existing label after it
<?php echo $this->formLabel($form->get('username'), $labelSpan, 'append');
<?php echo $this->formInput($form->get('username');
</li>
<li>
<?php echo $this->formLabel($form->get('password'), $labelSpan, 'append');
<?php echo $this->formInput($form->get('password');
</li>
</ul>
Related
i have a list that contains entity classes with two variables (id and categoryname). My entity looks like this:
String categoryName;
int categoryID;
//getters and setters
My controller class returns a List of all categories using
service.findAll();
Normally an iteration over this kind of list is one element at a time. My question is I want to be able to get two elements at a tome from the list to enable me populate the UI, which has two columns. Or in more simpler terms, how can I iterate over two elements at once in a List?
<div class="flex items-center justify-between space-x-3">
<div>
<input type="checkbox" name="category" th:value="${category.id}"> <label th:text="${category.categoryName}">
</div>
<div>
<input type="checkbox" name="category" th:value="${category.id}"> <label th:text="${category.categoryName}">
</div>
</div>
This should probably work:
<th:block th:each="i: ${#numbers.sequence(0, list.size()-1, 2)}">
//Edit: I added -1 to list.size()
<div class="flex items-center justify-between space-x-3">
<div>
<input type="checkbox" name="category" th:value="${list[i].id}">
<label th:text="${list[i].categoryName}">
</div>
<div>
<input type="checkbox" name="category" th:value="${list[i+1].id}">
<label th:text="${list[i+1].categoryName}">
</div>
</div>
</th:block>
You will have to do something if the size of the list is not a multiple of 2, unless you know for sure this will always be the case.
PS: I wonder if maybe it is better to use a normal iteration and use CSS to choose how many columns you show depending on screen width for example.
For a very specific use case, after a transaction I need to login into another system (build with Angular) to fill in a form. Login works OK, navigating to the correct link to create a new record showing the modal form works. Now there is a field I need to enter which autopopulates a list in style of
<ul>
<li><a class="ng-scope ng-binding"><strong>AAA</strong></a></li>
<li><a class="ng-scope ng-binding"><strong>BBB</strong></a></li>
</ul>
None of the UL, LI, or A elements have an id or a name. How can I select the first option from the LI?
rails 5.2
capybara
selenium
html snippet of the page
<form id="addedit-transfer_form" class="form-horizontal form-condensed ng-scope ng-invalid ng-invalid-required ng-dirty" ng-controller="RepeaterCtrl">
<!-- ngRepeat: line in repeaterLines --><table class="table table-striped table-condensed ng-scope" ng-repeat="line in repeaterLines">
<tr class="offset1">
<td>
<input name="model[0][Destinations][0][ShipmentLicenseType]" type="hidden" value="Licensed">
<div class="control-group">
<label class="control-label"><strong class="ng-binding">Destination 1</strong></label>
<div class="controls">
<div class="input-append">
<input autocomplete="off" class="js-validated-element validate[required] ng-dirty ng-invalid ng-invalid-required" placeholder="Type part of the License Number..." required="" spellcheck="false" type="text" ng-model="destination.RecipientId" typeahead="facility.Id as facility.LicenseNumber + ' | ' + facility.FacilityName for facility in preload.repeaterData.DestinationFacilities | orderBy:'LicenseNumber' | filter:$viewValue | limitTo:10" typeahead-editable="true" ng-blur="globalMethods.typeaheadValidator(preload.repeaterData.DestinationFacilities, 'Id', destination, 'RecipientId');" typeahead-input-formatter="globalMethods.typeaheadFormatter(preload.repeaterData.DestinationFacilities, destination.RecipientId, 'Id', 'LicenseNumber');" typeahead-on-select="validateSelection(preload.repeaterData.DestinationFacilities, [[$parent.$index, 'Destinations', 'Transfer'], $index], ['Id', 'RecipientId'], 'LicenseNumber', false, false, preload.defaults.destinationLine);" id="form-validation-field-0">
<ul class="typeahead dropdown-menu ng-isolate-scope" ng-style="{display: isOpen()&&'block' || 'none', top: position.top+'px', left: position.left+'px'}" typeahead-popup="" matches="matches" active="activeIdx" select="select(activeIdx)" query="query" position="position" style="display: block; top: 57px; left: 182px;">
<!-- ngRepeat: match in matches --><li ng-repeat="match in matches" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)" class="ng-scope active">
<a tabindex="-1" bind-html-unsafe="match.label | typeaheadHighlight:query" class="ng-scope ng-binding"><strong>020-100815612A0</strong> | 12/12 INDO</a>
</li><!-- end ngRepeat: match in matches -->
</ul>
<button class="js-destinationsearch-0-0 btn js-destinationsearch" data-id-field="Id,RecipientId" data-index="0" data-sublists="0,Destinations" data-sibling-validator="typeahead-on-select" data-popover-updater="" type="button" data-original-title="" title="">
<span class="icon-search"></span>
</button>
<input name="model[0][Destinations][0][RecipientId]" type="hidden" value="">
</div>
<button class="btn btn-info btn-mini" type="button" ng-click="removeLine($index, line.Destinations, true, preload.defaults.destinationLine); preload.methods.createNewControls();">
<span class="icon-minus-sign ng-hide" ng-hide="line.Destinations.length === 1"></span><span ng-show="line.Destinations.length === 1" class="">(clear)</span>
</button>
</div>
</div>
enter correct info in the field with placeholder placeholder="Type part of the License Number..." works then showing the ul/li part which requires a select to set the hidden field
You don't mention how you need to select from that list, but if you just need to click it you could do
click_link('AAA')
If you need more specific than that you could do
find('li > a', text: 'AAA').click
etc.
This assumes you've already sent the relevant keystrokes to the input to make the list appear.
I am using the following html for feeding user name and on losing the focus want the email input field to fill up with username + '#gmail.com'. But the Value setting is not giving the desired result.
HTML code is
<div class="form-group" >
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" name="name" onfocusout= "seteMail(this)" class="form-control" placeholder="Enter Personal Number as User Name" maxlength="7" value="<?php echo $name ?>" required/>
<span class="text-danger"><?php echo $nameError; ?></span>
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
<input type="email" name="email" class="form-control" placeholder="Enter AFNET eMail ID" maxlength="40" value="<?php echo $email ?>" required/>
<span class="text-danger"><?php echo $emailError; ?></span>
</div>
</div>
javascript is
function seteMail(thisvalue) {
// window.alert(thisvalue.value);
var tempval = thisvalue.value.toString()+'#gmail.com';
$('#email').val(tempval);
$('#email').html(tempval);
};
<input> is an input field and can never be set externally as it takes input only from the Standard Input that is Keyboard.
I have realised this after lots of H&T Method (H&TM).
I have simple application in zf2, I have menu in layout which is for each page of application. e.g., provinces/index.phtml, districts/index.phtml, cities/index.phtml etc.
Menu is:
<li class="start active ">
<a href="admin">
<i class="fa fa-home"></i>
<span class="title">
Dashboard
</span>
<span class="selected">
</span>
</a>
</li>
<li>
<a href="provinces">
<i class="fa fa-globe"></i>
<span class="title">
Provinces
</span>
</a>
</li>
<li>
<a href="districts">
<i class="fa fa-map-marker"></i>
<span class="title">
Districts
</span>
</a>
</li>
<li>
<a href="cities">
<i class="fa fa-tint"></i>
<span class="title">
Cities
</span>
</a>
</li>
I have code:
<div class="page-content-wrapper">
<?php echo $this->content; ?> <!--this print contents of index.phtml -->
</div>
which access each page in the same layout.
Now I want to make menu dynamically, i.e., when provinces is selected then provinces should highlighted, if districts is selected then districts in menu should be highlighted.
I tried the logic like below:
In provinces/index.phtml I write the code $selected_page="provinces", in districts/index.phtml I write the code $selected_page="districts" etc
Then in menu in layout:
I write class="start active" >
same is for districts and provinces etc.
But here variable $selected_page can not accessed, because
<?php echo $this->content; ?>
can only print and display content of index.phtml, and variable is not passed to layout.
So how should I do this? how should I pass variable $current_page to layout, or show me other logic about it.
Thanks in advance:
screenshot is given below with Dashboard highlighted:
If you want to pass variable from controller/action (for example provincesAction()) to view. Use layout() controller plugin:
public function provincesAction()
{
$this->layout()->setVariable('foo', 'bar');
return new ViewModel([]);
}
In layout.phtml
// html code
<?php echo $this->foo; ?> // It will display "bar"
// more html code
But for your example. I would suggest you to use navigation() view helper. Read more on https://framework.zend.com/manual/2.4/en/modules/zend.navigation.view.helper.menu.html. This plugin is made just for such things like you need.
I am using ZF2, few of my fields are created customarily due to design. While few are created via zend form. THe thing is that when i post data i get only those fields posted that are created via ZF2 form e.g my username field, gender, title. Rest of fields are not posted. Here is the snippet to my code
<?php
$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form);
?>
<div class="featureBox">
<div class="profile_address">
<div class="main">
<div class="address_head"><h4><?php echo $form->get('username')->getValue(); ?> > Account Detail</h4></div>
<div class="field_set">
<div class="field_input">
<label><?php echo $form->get('username')->getLabel(); ?></label>
<div class="field"><input type="text" readonly="readonly"value="<?php echo $form->get('username')->getValue(); ?>"></div>
</div>
<div class="field_input">
<label><?php echo $form->get('email')->getLabel(); ?></label>
<div class="field"><input type="text" value="<?php echo $form->get('email')->getValue(); ?>"></div>
</div>
</div>
</div>
<div class="field_set">
<div class="field_input">
<?php echo $this->formRow($form->get('gender')->setAttribute('class', 'stylish-select')); ?>
</div>
</div>
<div class="field_set">
<div class="field_input">
<?php echo $this->formRow($form->get('title')); ?>
</div>
</div>
<div class="free-btn">
<input type="submit" value="Save" onclick="return validatePassword();"/>
<input type="button" value="Back" class="button" onclick="window.location='<?php echo $this->url('admin_administrator'); ?>';return false;" />
</div>
</div>
</div>
</div>
<?php
$this->form()->closeTag();
?>
Any idea on whats getting wrong i can over come this if i use
$this->formRow()
with all fields but if i use this it will ruin my design requirements.
Your inputs don't have a name attribute, for example
<input type="text" value="<?php echo $form->get('email')->getValue(); ?>">
Should be
<input type="text" name="email" value="<?php echo $form->get('email')->getValue(); ?>">
missing------------^