Auto fill radio button in volt template without using model - phalcon

I rendered elements of a form in volt file using below code. I want to auto fill the default radio button.
<div class="form-group" >
<div><label>Gender *:</label>
<label class="radio-inline popup-gender">{{ element }}{{ element.label()}}:</label>
</div>

If you're using PHP to prepare the form:
$radio = new Radio('my_radio', ['id' => null, 'value' => 'one']);
$radio->setDefault('one');
$form->add($radio);
$radio = new Radio('my_radio', ['id' => null, 'value' => 'two']);
$form->add($radio);
If you're using Volt:
{{ set_default('my_radio', 'one') }}
{{ radio_field('my_radio', ['id' => null, 'value' => 'one']) }}
{{ radio_field('my_radio', ['id' => null, 'value' => 'two']) }}

Related

Pass attributes / props as array

I want to use an array and use it to fill the props of a laravel-blade (8.x) component dynamically. In short something like that:
<x-button size="sm" {{ $buttonProps }} /> where $buttonProps is an array with key-value pairs defining the props and its values for the button to render.
The array would look like this: ['label' => 'My Button', 'size' => 'sm', ...]
Here is a more in detail example of what I try to do:
1. Button component with some props
#props([
'size' => 'md', # sm, md, lg
'variant' => 'basic', # basic, success, error
'label' => '',
])
#php
// ...
#endphp
<button {{ $attributes->merge([ 'class' => '...' ]) }}>
{!! $label !!}
</button>
2. ButtonGroup - which will render the Buttons using an array for their props
Here is the thing which doesn't work: {{ $buttonProps }}. I want to dynamically pass down the props for the Button as an array. But this solution doesn't work like that of course. Is there a solution how I can do that?
#props([
'buttons' => []
])
<div class="...">
#foreach ($buttons as $buttonProps)
<x-button size="sm" {{ $buttonProps }} />
#endforeach
</div>
3. Finally how I would use the ButtonGroup in this scenario
You may notice that I pass some extra prop to the first button. That's basically why I need a dynamic approach as I don't know all the props passed in my real-life scenario.
<x-button-group
:buttons="[
[
'label' => 'Export',
'hello' => 'world',
'type' => 'button',
'onclick' => '() => alert(\'hello world\')',
],
[
'label' => 'Main action',
'variant' => 'accent',
]
]"
/>
Note: I know I could easily make this example running using slots here, but my real-life example is a little different in requirements. I used Button and ButtonGroup as an example to illustrate my problem.
You don't seem to have shown where is the array of $buttons coming from.. You do foreach on $buttons.Investigate that part.

Custom wordpress taxonomy with v2 api and vue

I'm using the wordpress v2 api to display custom posttypes. Everything works as expected, only the custom taxonomy returns their ID instead of the name.
I've read that adding ?embed to the endpoint and show_in_rest adds posttypes and taxonomies to the api result and this sort of looks to be the case. But the taxonomy name isn't found in the result.
Am I missing something?
Here are some snippets of my code...
// taxonomy snippet
register_taxonomy('types',array('work'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'type' ),
'show_in_rest' => true,
'rest_base' => 'work-api',
'rest_controller_class' => 'WP_REST_Terms_Controller'
// custom posttype snippet
$args = array(
'labels' => $labels,
'description' => 'All projects',
'public' => true,
'menu_icon' => 'dashicons-layout',
'supports' => array('title', 'editor', 'thumbnail'),
'has_archive' => true,
'show_in_rest' => true,
'rest_base' => 'work-api',
'rest_controller_class' => 'WP_REST_Posts_Controller'
);
// DOM snippet
<div id="workfeed" class="work" style="margin-top: 100px;">
<div v-for="(item,index) in work" class="row" :data-index="index">
<div class="col">
<img :src="item._embedded['wp:featuredmedia'][0].source_url" />
</div>
<div class="col">
<h3>{{ item.title.rendered }}</h3>
{{ item.content.rendered }}
{{ item._embedded['wp:term'][0].taxonomy }}
</div>
</div>
</div>

Add field in product Prestashop 1.7

Why is prestashop don't save my modification into database?
Using prestashop 1.7
/override/classes/Product.php
class Product extends ProductCore {
public $por_gan; public function __construct ($idProduct = null, $idLang = null, $idShop = null) {
$definition = self::$definition;
$definition['fields']['por_gan'] = array('type' => self::TYPE_INT, 'required' => false);
parent::__construct($idProduct, $idLang, $idShop); } }
In ProductInformation.php
->add('por_gan', 'Symfony\Component\Form\Extension\Core\Type\NumberType', array(
'required' => false,
'label' => $this->translator->trans('Beneficio', [], 'Admin.Catalog.Feature'),
'constraints' => array(
new Assert\NotBlank(),
new Assert\Type(array('type' => 'numeric'))
),
))
In form.html.twing
<div class="col-md-6">
<label class="form-control-label">% de beneficio</label
{{ form_widget(form.step1.por_gan) }}
</div>
Thanks
I’ve successfully added an extra tab in admin product page.
It's working fine. I think a better approach would be to create a module in order to make that modification easier to maintain.
Or you can use displayAdminProductsExtra hook, actionProductUpdate hook and actionProductAdd
The extra field is : frais_a_prevoir
I show all the files to modify but you have to check where the modification should be done inside the file (make a search and you will find)
Override /classes/Product.php
In class /classes/Product.php, there are 3 modifications to do :
1)
/** #var string Frais à prévoir */
public $frais_a_prevoir;
2)
'frais_a_prevoir' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
3)
$sql->select(
'p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`frais_a_prevoir`, pl.`link_rewrite`, pl.`meta_description`,
pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`, image_shop.`id_image` id_image, il.`legend`, m.`name` AS manufacturer_name,
(DATEDIFF(product_shop.`date_add`,
DATE_SUB(
"'.$now.'",
INTERVAL '.$nb_days_new_product.' DAY
)
) > 0) as new'
);
In /src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig
<ul class="nav nav-tabs bordered">
<li id="tab_description_short" class="nav-item">{{ 'Summary'|trans({}, 'Admin.Catalog.Feature') }}</li>
<li id="tab_description" class="nav-item">{{ 'Description'|trans({}, 'Admin.Global') }}</li>
<li id="tab_frais_a_prevoir" class="nav-item">{{ 'frais_a_prevoir'|trans({}, 'Admin.Global') }}</li>
</ul>
<div class="tab-content bordered">
<div class="tab-pane panel panel-default active" id="description_short">
{{ form_widget(form.step1.description_short) }}
</div>
<div class="tab-pane panel panel-default " id="description">
{{ form_widget(form.step1.description) }}
</div>
<div class="tab-pane panel panel-default " id="frais_a_prevoir">
{{ form_widget(form.step1.frais_a_prevoir) }}
</div>
</div>
In /src/PrestaShopBundle/Form/Admin/Product/productInformation.php
->add('frais_a_prevoir', 'PrestaShopBundle\Form\Admin\Type\TranslateType', array(
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextareaType',
'options' => [
'attr' => array('class' => 'autoload_rte'),
'required' => false
],
'locales' => $this->locales,
'hideTabs' => true,
'label' => $this->translator->trans('frais_a_prevoir', [], 'Admin.Global'),
'required' => false
))
in src/PrestaShopBundle/Model/Product/AdminModelAdapter.php:
$this->translatableKeys = array(
'name',
'description',
'description_short',
'frais_a_prevoir',
'link_rewrite',
'meta_title',
'meta_description',
'available_now',
'available_later',
'tags',
);
//define unused key for manual binding
$this->unmapKeys = array('name',
'description',
'description_short',
'frais_a_prevoir',
'images',
'related_products',
'categories',
'suppliers',
'display_options',
'features',
'specific_price',
'virtual_product',
'attachment_product',
);
2)
'frais_a_prevoir' => $this->product->frais_a_prevoir,
In database, add a column frais_a_prevoir in table product_lang
Here is an option to do this using module and does not change core files
in your MyModule.php
use PrestaShopBundle\Form\Admin\Type\TranslateType;
use PrestaShopBundle\Form\Admin\Type\FormattedTextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
public function hookDisplayAdminProductsExtra($params)
{
$productAdapter = $this->get('prestashop.adapter.data_provider.product');
$product = $productAdapter->getProduct($params['id_product']);
$formData = [
'ebay_reference' => $product->ebay_reference,
];
$formFactory = $this->get('form.factory');
$form = $formFactory->createBuilder(FormType::class, $formData)
->add('ebay_reference', TranslateType::class, array(
'required' => false,
'label' => 'Ebay reference',
'locales' => Language::getLanguages(),
'hideTabs' => true,
'required' => false
))
->getForm()
;
return $this->get('twig')->render(_PS_MODULE_DIR_.'MyModule/views/display-admin-products-extra.html.twig', [
'form' => $form->createView()
]) ;
}
public function hookActionAdminProductsControllerSaveBefore($params)
{
$productAdapter = $this->get('prestashop.adapter.data_provider.product');
$product = $productAdapter->getProduct($_REQUEST['form']['id_product']);
foreach(Language::getLanguages() as $language){
$product->ebay_reference[ $language['id_lang'] ] =
$_REQUEST['form']['ebay_reference'][$language['id_lang']];
}
$product->save();
}
in your display-admin-products-extra.html.twig
<div class="row" >
<div class="col-md-12">
<div class="form-group">
<h3>Ebay reference</h3>
{{ form_errors(form.ebay_reference) }}
{{ form_widget(form.ebay_reference) }}
</div>
</div>
</div>

Laravel 4 password confirm doesn't seem to work how I expect it to

I am basing my code off of a video on Laracasts.com. Here is the video. My idea is that I could use that validation method to create a user. When I try to confirm the passwords, it doesn't seem to match no matter what. My initial thought was that it is hashing the password prior to validation which causes it to return false no matter what.
Here's all of my code thus far.
Users Model
protected $fillable = ['username' ,'email', 'password'];
public static $rules = [
'username' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed'
];
public function isValid()
{
$validation = Validator::make($this->attributes, static::$rules);
if ($validation->passes()) return true;
$this->errors = $validation->messages();
return false;
}
UsersController#Store
public function store()
{
$input = Input::all();
if (! $this->user->fill($input)->isValid())
{
return Redirect::back()->withInput()->withErrors($this->user->errors);
}
//if the user input is valid then save it and assign associated role
$this->user->save();
$this->user->assignRole(Input::get('role'));
return Redirect::to('/user')->with('flash_message', 'User added to the database!');
}
Create User View - Form
{{ Form::open(['role' => 'form', 'route' => 'user.store']) }}
<div class='form-group'>
{{ Form::label('username', 'First Name') }}
{{ Form::text('username', null, ['placeholder' => 'First Name', 'class' => 'form-control']) }}
</div>
<div class='form-group'>
{{ Form::label('email', 'Email') }}
{{ Form::text('email', null, ['placeholder' => 'Last Name', 'class' => 'form-control']) }}
</div>
<div class='form-group'>
{{ Form::label('role', 'Role') }}
{{ Form::select('role', $roles, "member", ['class' => 'form-control']) }}
</div>
<div class='form-group'>
{{ Form::label('password', 'Password') }}
{{ Form::password('password', ['placeholder' => 'Password', 'class' => 'form-control']) }}
</div>
<div class='form-group'>
{{ Form::label('password_confirmation', 'Password Confirm') }}
{{ Form::password('password_confirmation', ['placeholder' => 'Password Confirm', 'class' => 'form-control']) }}
</div>
<div class='form-group'>
{{ Form::submit('Create User', ['class' => 'btn btn-primary']) }}
</div>
{{ Form::close() }}
What's happening is that your password_confirmation field is always empty, no matter what you enter.
This is because you are using $this->user->fill($input) within the store method. However, in your model you have
protected $fillable = ['username' ,'email', 'password'];
So, this will never fill the password_confirmation field.
If you change the fillable to the following, you should have no problems
protected $fillable = ['username' ,'email', 'password', 'password_confirmation'];

How to show timepicker based jqrelcopy yii?

How to show timepicker based yiibooster, with Jqrelcopy.
I've code like this :
<div class="control-group "><label class="control-label required">Jam Kerja</label>
<div class="controls">
<a id="copylink" href="#" rel=".copy">Tambah Jam Kerja / Shift</a>
<div class="row copy">
<?php echo CHtml::label('',''); ?>
<?php $this->widget('bootstrap.widgets.TbTimePicker',
array(
'name' => 'some_time',
'value' => '00:00',
'htmlOptions'=>array('width'=>'50px'),
'noAppend' => true, // mandatory
'options' => array(
'disableFocus' => true, // mandatory
'showMeridian' => false // irrelevant
),
)
);
?>
<?php
$this->widget('bootstrap.widgets.TbTimePicker',
array(
'name' => 'some_time',
'value' => '00:00',
'noAppend' => true, // mandatory
'options' => array(
'disableFocus' => true, // mandatory
'showMeridian' => false // irrelevant
)
)
);
?>
</div>
</div>
</div>
When I add new, Timepicker always on field 1. Can't on field changed.