Symfony 1.4 Label position in a form - forms

Is there a way to change the position of the label in a form? I would like to have it above the input field (sfWidgetFormInputText and sfWidgetFormChoice) . Is that possible?

Depends on how you're rendering the form field. You can do it a few ways:
If you want to render an individual field differently to the rest in your form, you can render the label and widget separately like this in your template:
// \apps\myApp\modules\myModule\templates\_form.php
echo $form['field_name']->renderLabel(); // Render the label
echo $form['field_name']->render(); // Render the widget
echo $form['field_name']->renderError(); // Render the error
echo $form['field_name']->renderHelp(); // Render the help message
If you want to apply the layout across your entire form. You should create a new formatter class and apply it to your form:
// \lib\form\formatter\sfWidgetFormSchemaFormatterCustom.class.php
class sfWidgetFormSchemaFormatterCustom extends sfWidgetFormSchemaFormatter
{
protected
$rowFormat = '<div class="label">%label%</div><div class="field">%field%</div>%error% \n %help %hidden_fields%',
$errorRowFormat = '<div>%errors%</div>',
$helpFormat = '<div class="form_help">%help%</div>',
$decoratorFormat = '<div>\n %content%</div>';
}
Apply it in your form's configure method like this:
// \lib\form\myForm.class.php
public function configure()
{
//....
$formatter = new sfWidgetFormSchemaFormatterCustom($this->getWidgetSchema());
$this->widgetSchema->addFormFormatter('custom', $formatter);
$this->widgetSchema->setFormFormatterName('custom');
}
If you want the formatter to be used globally across your project, you can set it as the default formatter in your ProjectConfiguration.class.php.
// \config\ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
// ...
sfWidgetFormSchema::setDefaultFormFormatterName('custom');
}
}

You have to do it in the template associated with the form in which you can reorganize all the form using html tags (<th>, <tr>, <td> ....).

Related

AngularDart structural directive add custom content

Is there some chance to simple update _viewContainer??
I am trying create directive for material-button component, that add hidden classic button for submit form by hit enter key. I need to add simple html to _viewContainer, something like this
import 'package:angular/angular.dart';
#Directive(
selector: '[kpMaterialSubmit]',
)
class KpMaterialSubmit {
final TemplateRef _templateRef;
final ViewContainerRef _viewContainer;
KpMaterialSubmit(this._viewContainer, this._templateRef);
#Input()
set kpMaterialSubmit(bool showButton) {
_viewContainer.clear();
if (showButton) {
_viewContainer.createEmbeddedView(_templateRef);
//THIS IS THE IMPORTANT PART
_viewContainer.createMyCustomView('<button class="hidden">Submit</button>');
} else {
_viewContainer.createEmbeddedView(_templateRef);
}
}
}
I have done something similar and it works. I don't know if there is a better way.
Instead of using html text directly, create a component.
Add the import to the component template:
import 'package:<your package>/<path to component>/<component source name>.template.dart';
Then add the component with the createComponent() method (instead of createMyCustomView()):
_viewContainer.createComponent(<componentName>NgFactory);
That's all!
If you need to style the component or add any attribute you can get the reference and derive the HtmlElement instance:
ComponentRef _componentRef = _viewContainer.createComponent(<componentName>NgFactory);
HtmlElement element = _componentRef.location;
element.style.background = 'green';
element.setAttribute('value', 'text');

Display a custom field with Rendered in Product Grid UI Component in Magento 2

I want to add one custom field in Product Grid UI Component where It will display some text which will fetch from Product Custom Option.
I tried lots of solution but all are for other Grid system not the Magento 2 Product Grid UI Component. I found how to add a custom image but I want to display, one of my Custom Option in the Product Grid UI Component. Please help
as i understand from your question you want to add custom field to your Product grid. you can do that by creating custom action that have the grid.
in your Grid Class while adding the columns add your render like the following
$this->addColumn(
'coulmnName',
[
'header' => __('Title'),
'renderer'=>'\path\to\your\ClassName',
]
);
in your class add your stuff to render and return any data like the following
namespace your\class\path;
class ClassName extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
public function __construct(
\Magento\Backend\Block\Context $context,
array $data = []
)
{
parent::__construct($context, $data);
}
public function render(\Magento\Framework\DataObject $row)
{
//get any data from tour current Grid Column
$data = $row->getCoulmnName();
// do your stuff
return $anyData;
}

How to change the default wrapper (ie 'h2') of a form title in Zend Form

Iam using zend_Form for creating forms in my project
The form titles are wrapped by 'h2' tag in default.
How can i change it to 'h3' tag,so that particular form title will wrapped by 'h3' tag.
Following is my code
class Core_Form_Contact extends Zend_Form
{
public function init()
{
$this->setTitle('Contact Us');
}
}
Any one have idea?

zend form elements display hidden field value

$emailmessage = new Zend_Form_Element_Hidden('emailmessage');
the hidden filed value, i.e 'emailmessage' retrieves the value of the same field name inside the database. However on loading the page, value of the 'emailmessage' cannot be seen, since the element is hidden.
Is there any way to display it without using any other form elements. I want it without using text, textarea, etc.
in controller you need to assign it to view and in the view you can echo it where ever you want:
controller
$form = new Your_Form();
$this->view->emailmessage = $emailmessage;
View
echo $this->escape($this->emailmessage);
You need to set formNote decorator for the element.
You do it by extending Hidden element or by setting decorator in the form.
Form
public function init()
{
// ...
$emailMessage = new Zend_Form_Element_Hidden();
$emailMessage->setDecorators(
array(
array('ViewHelper', array('helper' => 'formNote'))
)
);
$this->addElement($emailMessage, 'emailMessage');
// ...
}

Way to define others layout() parts such layout()->content?

Ive done some search but no success.. i am trying to figure out how to define others layout() parts such layout()->content variable.. i would love to get int layout()->navigation (a custom one) which display the navigation..
Any ideas ?
Thanks.
Not sure if this is what you want, but you can create additional 'parts' of layout simply by assigning a value to your new part. ZF will take care of the rest. For example, in a bootstrap.php you could do:
public function _initNewLayoutPart() {
$view = $this->bootstrap('view')->getResource('view');
$view->layout()->newpart = 'some new part';
}
Then in your layout.phtml you could just echo the new part:
<?php echo $this->layout()->newpart; ?>
It is possible by just creating a new variable in layout, you can define it in your controller (preferably in init or postDispatch). Just like this:
public function init()
{
$this->view->layout()->motd = '<b>Message of the day.</b>';
}
Then in your actual view where you want to see the message, all you have to do is:
<?php echo $this->layout()->motd; ?>
If you want something fancier, such as rendering a whole page or sidebar, try the following:
public function init()
{
$this->view->layout()->sidebar = $this->view->action('render', 'sidebar');
}
With render being the action (including render.phtml) and sidebar being the controller.