I follow all the instruction on how to use yii2-jui datepicker and also i download the jquery-ui, i follow all the instruction on how to install and where to put those downloads, after that i try this code
<?= $form->field($model,'date')->widget(DatePicker::className(),['clientOptions' => ['defaultDate' => '2014-01-01']]) ?>
i also include the use yii\jui\DatePicker; but the DatePicker doesn't work the ouput is always like textInput
looking at my JS errors it appear this:
TypeError: jQuery(...).datepicker is not a function
I don't know problem, for more vision here is my code :
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\jui\DatePicker;
?>
<div class="payee">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'payee_id')->dropDownList(['a' => 'Item A', 'b' => 'Item B', 'c' => 'Item C'] )->label('Payee'); ?>
<?= $form->field($model, 'payee_address')->textInput(['style'=>'width: 400px', 'placeholder'=>'Address' ] )->label('Address'); ?>
<?= $form->field($model,'date')->widget(DatePicker::className(),['clientOptions' => ['defaultDate' => '2014-01-01']]) ?>
<?= $form->field($model, 'payee_number')->textInput(['style'=>'width: 400px', 'placeholder'=>'Disbursement #' ] )->label('Disbursement Number'); ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div><!-- payee -->
Thanks in advance.
I look at my jquery-ui, i there's no jquery-ui.js.
Related
I'm using Twitter Bootstrap 3. Html code for the radio buttons should look like:
<div class="radio">
<label>
<input type="radio" name="search_text_source" value="title" />
In the title
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="search_text_source" value="content" />
In the content
</label>
</div>
...
In the form, I create radio buttons as follows:
$this->add(array(
'name' => 'search_text_source',
'type' => 'radio',
'options' => array(
'value_options' => array(
'title' => 'In the title',
'content' => 'In the content',
'description' => 'In the description',
),
),
));
How do I get separate each radio button in view script?
P.S.: Or any decision, which will create like html code using the form.
EDIT:
Thanks to Sam figured out. But I will leave these variants for more complex cases. During the experiments, the following happened (with standart view helper):
// in view script:
<?
$this->formRadio()->setSeparator('</div><div class="radio">');
?>
<!-- some html -->
<div class="radio">
<?php echo $this->formRadio($form->get('search_text_source')) ?>
</div>
Once again, thank Sam for help, without him I would not understand.
Does anyone ever read the documentation? There's even a dedicated chapter for Zend\Form\View\Helper-Classes, that should answer all your questions.
Furthermore, since you'd probably want the TB3-Style for all your Form Elements, you may be interested in one of the many, many TB-Modules
// Edit
I don't see how the documentation does not answer your question :S I believe the default output of the formRadio() viewHelper is what you're looking for anyways, so all you need is a separate div, right?
// any.phtml
<?=$this->form()->openTag($form);?>
<div class="radio">
<?=$this->formRadio($form->get('radio1')); ?>
</div>
<?=$this->form()->closeTag();?>
// Edit2
And of course you always have the option of writing your very own formRadio() ViewHelper that writes out the div for you. There's an easy to find SO Question, just for this very topic available.
// Edit3
Feeling guilty in attitude, your ViewHelper could be as simple as this:
// Application\Form\View\Helper\FormRadio.php
namespace Application\Form\View\Helper;
use Zend\Form\View\Helper\FormRadio as OriginalFormRadio;
class FormRadio extends OriginalFormRadio
{
protected function renderOptions(/* include original attributes here */)
{
// Include 100% of Original FormMultiCheckbox Code
// https://github.com/zendframework/zf2/blob/master/library/Zend/Form/View/Helper/FormMultiCheckbox.php#L147
// Now change this one line #227 into your code
// Instead of: https://github.com/zendframework/zf2/blob/master/library/Zend/Form/View/Helper/FormMultiCheckbox.php#L227
$template = '<div class="radio">' . $labelOpen . '%s%s' . $labelClose . '</div>';
}
}
Then you gotta overwrite the default ViewHelper
// Inside Module Class
public function getViewHelperConfig()
{
return array(
'invokables' => array(
'formradio' => 'Application\Form\View\Helper\FormRadio'
)
);
}
Additional Information: In this example i overwrite the original formRadio, rather than formMultiCheckbox. This is because I imagine TB3 would have a different CSS Class for rendering Checkboxes and not Radio elements.
My solution is:
Form:
$this->add(array(
'type' => 'radio',
'name' => 'gender',
'options' => array(
'label' => 'Gender',
'value_options' => array(
'female' => array(
'value' => '1',
),
'male' => array(
'value' => '2',
),
),
),));
View:
<div class="form-group">
<?php
$form->get('gender')->setLabelAttributes(array('class' => 'col-sm-4'));
echo $this->formLabel($form->get('gender'));
?>
<div class="col-lg-8">
<?php
$element = $form->get('gender');
$options = $element->getOptions();
$options = $options['value_options'];
?>
<div class="rdio rdio-primary">
<input id="female" type="radio" <?php if ($element->getValue() == $options['female']['value']) echo 'checked="checked"' ?> name="<?php echo $element->getName() ?>" value="<?php echo $options['female']['value'] ?>">
<label for="female">Female</label>
</div>
<div class="rdio rdio-primary">
<input id="male" type="radio" <?php if ($element->getValue() == $options['male']['value']) echo 'checked="checked"' ?> name="<?php echo $element->getName() ?>" value="<?php echo $options['male']['value'] ?>">
<label for="male">Male</label>
</div>
</div>
For more details you can study the code given on :
ZF2 rendering individual radio elements with helpers
while creating form, form validation is easy. But how can one validate submitted data and pass error message back to form.
For example I have a form for password change, SO I need to verify old password and check if new password and confirm password are same, and in failure stage, Show message on password edit form.
You mean that in your view script ?
<?php if ($form->getMessages()){
// alert
?>
<div class="alert alert-error">
<button class="close" data-dismiss="alert" type="button">×</button>
<strong><?php echo $this->translate("Are you awake ?"); ?></strong>
<?php echo $this->translate("Some data are not filled out correctly."); ?>
</div>
<?php
}?>
After just print the errors from $form->getMessages()
If setup correctly the form will do this for you. The form will run the validation checks and then you can use the formElementErrors view helper to disalay the errors.
Can you paste some code of how your form is setup?
An example of display validation errors in the form view:
<?php $form->prepare() ?>
<?php echo $this->form()->openTag($form); ?>
<?php foreach($form->getElements() as $element): ?>
<div class="control-group">
<?php /* #var $element \Zend\From\Element */ ?>
<?php if($element->getLabel()): ?>
<?php echo $this->formLabel($element) ?>
<?php endif ?>
<?php // Show any validation errors for this element ?>
<?php echo $this->formElementErrors($element); ?>
<?php echo $this->formElement($element) ?>
</div>
<?php endforeach ?>
<?php echo $this->form()->closeTag() ?>
Is there a way to just set the body in Zend Framework 2? In Zend Framework 1 I could do it this way
$this->getResponse()->setBody('Hello World')
I found a way to set content in Zend Framework 2 but this also overwrites the layout and that's not what I want.
Here is another way to do that....
ModuleName/src/ModuleName/Controller/IndexController.php
<?PHP
namespace ModuleName\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
protected $helloWorldTable;
public function indexAction()
{
return new ViewModel(array(
'foo' => 'Hello World From Zend Framework 2!',
));
}
}
ModuleName/view/ModuleName/index/index.phtml
<?PHP
$this->headTitle('Some Site...');
echo "$hello";
?>
Application/view/layout/layout.phtml
doctype(); ?>
<html lang="en">
<head>
<meta charset="utf-8">
<?php echo $this->headMeta()->appendName('viewport', 'width=device-width, initial-scale=1.0') ?>
<!-- Le styles -->
<?php echo $this->headLink(array('rel' => 'shortcut icon', 'type' => 'image/vnd.microsoft.icon', 'href' => $this->basePath() . '/images/favicon.ico')) ?>
<!-- Scripts -->
<?php echo $this->headScript()->prependFile($this->basePath() . '/js/html5.js', 'text/javascript', array('conditional' => 'lt IE 9',))
->prependFile($this->basePath() . '/js/bootstrap.min.js')
->prependFile($this->basePath() . '/js/jquery.min.js') ?>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="<?php echo $this->url('index') ?>"><?php echo $this->translate('Spamus') ?></a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="active"><?php echo $this->translate('Home') ?></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<?php echo $this->content; ?>
<hr>
<footer>
<p>© 2012 - 2013 by YourSite <?php echo $this->translate('All rights reserved.') ?></p>
</footer>
</div> <!-- /container -->
<?php echo $this->inlineScript() ?>
</body>
</html>
Whatever you changed Response body in controller, when zf2 MvcEvent::EVENT_RENDER trigger, a new Response body will be rebuilt. So correct way is change Response body AFTER MvcEvent::EVENT_RENDER.
Add this to your controller:
$this->getServiceLocator()->get('Application')->getEventManager()->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function($event){
$event->getResponse()->setContent('foobar');
}, -10000);
I finally got the solution. To change the content in the layout, just type in controller's action
$this->layout()->content = 'foobar';
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Parse error: syntax error, unexpected T_STRING in app/design/frontend/base/default/template/catalog/product/new.phtml on line 37:
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
How to modify it.Thanks in advance.
Just it was showed on home page.
original:
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135) ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
<h3 class="product-name"><?php echo $this->htmlEscape(Mage::helper('core/string')->truncate($_product->getName(),60,'鈥?)); ?></h3>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php echo $this->getPriceHtml($_product, true, '-new') ?>
<div ><img src="http://www.onlyforcars.com/images/freeshipping.jpg" width="97" height="14" alt="Free Shipping" /></div>
<div class="actions">
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a rel="nofollow" href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php if ($_compareUrl = $this->getAddToCompareUrl($_product)): ?>
<li><span class="separator">|</span> <a rel="nofollow" href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
</ul>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
</ul>
<?php endif ?>
<?php endforeach; ?>
This is caused by the third param of your Mage::helper('core/string')->truncate() call, where the ending string delimiter seems to be missing.
You get the unexpected T_STRING error, because the interpreter reaches the next string ('short'), while knowing that the previous string end wasn't found yet.
Replace this line
<h3 class="product-name"><?php echo $this->htmlEscape(Mage::helper('core/string')->truncate($_product->getName(),60,'鈥?)); ?></h3>
with this line
<h3 class="product-name"><?php echo $this->htmlEscape(Mage::helper('core/string')->truncate($_product->getName(),60,'鈥?')); ?></h3>
I'm currently extending a Site and do not have much experience with symfony.
Currently there is a Search-Form which looks like this:
<form id="search_huts_form" action="<?php echo url_for('hut/search') ?>" method="get">
<fieldset>
<legend><strong><?php echo __('Search huts') ?></strong></legend>
<table id="spielplantabelle">
<tr>
<td><?php echo __('Your arrival date?') ?></td>
<td>
<select name="arrival">
<option value=""><?php echo __('no preference') ?></option>
<?php foreach ($checkInDates as $date): ?>
<option value="<?php echo $date ?>"><?php echo $date ?></option>
<?php endforeach; ?>
</select>
</table>
<input type="submit" value="<?php echo __('Search') ?>" name="Submit" class="inputbuchen" />
</fieldset>
</form>
Now I have to create a list of Categories below the search form with special offers which can also be found with the search function used in the form. This is what I have so far:
<ul>
<?php foreach ($types as $typ): ?>
<?php if (preg_match('#[0-9]#',$typ)): ?>
<li> <?php echo($typ) ?> </li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
The links correctly forward to the search page but I have no idea hot to set parameters based on the link a user clicks. Is this possible?
I hope I get your problem right.
You could add some additional url parameters to the link.
e.g.
<li> <a href="<?php echo url_for('hut/search?id='.$id) ?>"><?php echo($typ) ?>
You can then query this id on the page you've opened.
$request->getGetParameter('id');
Hope this helps.