This is my dropdownlistFor
#Html.DropDownListFor(m => m.objTicket.DepartmentId, new SelectList(Model.objTicket.Departments, "DepartmentId", "Department"),
"-- Select Department--", new { id = "Deptment"}, disabled="disabled")
How can I pass the value which is already stored in objTicket.DepartmentId ?
If i change remove disabled ="disabled", i get my correct value.
Form fields are submitted using Names instead of Ids. Disabled controls values wont be submitted by browsers. Place a #Html.HiddenFor field with same name and different Ids as given below.
#Html.DropDownListFor(m => m.objTicket.DepartmentId, new SelectList(Model.objTicket.Departments, "DepartmentId", "Department"),Department--", new { id = "Deptment"}, disabled="disabled")
#Html.HiddenFor(m => m.objTicket.DepartmentId, new { id="Deptment2" })
Related
I have socialite login for facebook and google. I'm trying to store values in db. Some of them are stored and some no. I think I have tried everything, but can't find problem and solution.
I have function:
public function CreateUser($user, $provider)
{
$authUser = User::where('social_id', $user->id)->first();
if($authUser)
{
return $authUser;
}
$token = $this->generateRandomString();
return User::create([
'name' => $user->name,
'email' => $user->email,
'social' => $provider,
'social_id' => $user->id,
'username' => $this->user_slug($user->name),
'user_token' => $token,
'earnings' => 0,
'user_type' => 'vendor',
'verified' => 1,
]);
}
All Values except social and social_id are stored in database. I tried to store different values in different fields.
For example, if I store $provider value in 'name' field it works. if I try to store $provider value or any other value in 'social' field. DB dosn't store it. Same for 'social_id' field.
I tried saving same value in different fields - It works
I tried to save different values in fields 'social' and 'social_id' - It dosn't work.
I tried to rename these 2 fields - Still dosn't work
If I edit these fields from "phpmyadmin" then it works.
I tried to set fields with different options - It dosn't change anything
DB Photo
you should define which model attributes you want to make mass assignable. You may do this using the $fillable property on the model. For example, let's make the name attribute of our User model mass assignable:
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = ['social', 'social_id'];
}
We have an existing customization that appears to have broken when we upgraded from 1.7 to 1.9 community.
The customization adds a column to the associated products grid.
The customization is a local override of
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php
This was done before I started on the project
$this->addColumn('breakdown_part_no', array(
'header' => Mage::helper('catalog')->__('Part No'),
'name' => 'breakdown_part_no',
'type' => 'varchar',
'index' => 'breakdown_part_no',
'width' => '120px',
'editable' => true,
));
This was added to _prepareColumns()
Another customization was added to method getSelectedGroupedProducts()
public function getSelectedGroupedProducts()
{
$associatedProducts = Mage::registry('current_product')->getTypeInstance(true)
->getAssociatedProducts(Mage::registry('current_product'));
$products = array();
foreach ($associatedProducts as $product) {
$products[$product->getId()] = array(
'qty' => $product->getQty(),
'position' => $product->getPosition(),
'breakdown_part_no' => $product->getBreakdownPartNo(),
);
}
return $products;
}
The behavior is that the column appears in the admin and can be edited, however when saved, it does not save any value.
If I modify the getSelectedGroupedProducts part and set a hard coded value, it displays still no value (blank field), but interestingly if I click save with no value, it saves the value that was hard coded. If I enter any value in the field, it saves as a blank. This is really strange behavior that makes no sense to me.
If I change one of the other fields, such as position to be a hard coded value, it appears instantly and works as expected. Please let me know the proper way for this to work.
There are several posts on various forums about how to do the above and the modification mentioned is true, but what all of the other posts left out was the adminhtml layout input. When a user edits product data in Magento Admin (Associated Products), the data is serialized and sent to the controller save action. I noticed that the fields were not present when a value was entered. This is because the value wasn't in the layout so it was being stripped off of the request before it was posted to the controller.
Add input field in adminhtml/default/default/layout/catalog.xml
adminhtml_catalog_product_supergroup
addColumnInputName
I've added a new field to the Taxon entity, and have the new field showing up on the form on the edit Taxon page in the admin panel. My problem is that I can't get my new field to save to the Taxon. I receive a success message, but only existing Taxon fields save, while my new field clears. Here's my code (note I'm making changes to Sylius core rather than extending, as proof of concept. Once I have this working, I'll extend properly):
src/Sylius/Bundle/TaxonomyBundle/Form/Type/TaxonType.php:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('translations', 'sylius_translations', [
'type' => 'sylius_taxon_translation',
'label' => 'sylius.form.taxon.name',
])
->add('my_new_field', 'text', [
'label' => 'My New Field',
'required' => false
])
->addEventSubscriber(new AddCodeFormSubscriber())
->addEventSubscriber(new BuildTaxonFormSubscriber($builder->getFormFactory())
);
}
src/Sylius/Component/Core/Model/Taxon.php:
protected $my_new_field;
and
public function getMyNewField() {
return $this->my_new_field;
}
public function setMyNewField($myNewField) {
$this->my_new_field = $myNewField;
}
After updating the Taxon model, I ran doctrine:diff and then ran the migration to add my new field to the model. I can confirm, the field was added to the database.
The field also shows up on Taxons now, on the edit screen. I can input text into the field and it posts correctly, but does not ever save to the taxon.
I would think I'm missing some controller logic, but it seems that taxons go through the standard ResourceController's updateAction() and I haven't been able to figure out how to make this aware of the new field which needs to be saved.
You're probably missing ORM mapping in Taxon.orm.xml file.
Remember:
if you've added your properties on Sylius\Component\Taxonomy\Model\Taxon you have to update src/Sylius/Bundle/TaxonomyBundle/Resources/config/doctrine/model/Taxon.orm.xml.
if you've added your properties on Sylius\Component\Core\Model\Taxon you have to update src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/Taxon.orm.xml
It's also probably better to extend Taxon model from Core component.
I have a Model who has a column (attribute) that stored a comma separated value of IDs.
For Example,
Movie has a column "Genre" that includes more than one genre, e.g.: 40,20,1,3
How can I use Select2 widget to show these values separated when 'multiple' => true
And how can I save them back into comma-separated value as a string. I want a solution that will allow for quick flexibility. I know you can implode and explode the string but seems too much.
Any help appreciated
If I remember correctly pass the default option as part of the $options configuration for the widget:
echo $form->field($model, 'model_attribute_name')->widget(Select2::className(), [
'data' => $data
'options' => [
'class' => 'form-control',
'placeholder' => 'Choose Option...',
'selected' => 40
],
'pluginOptions' => [
'allowClear' => true,
],
])->label('Select2 Form Field');
This is from memory for grain fo salt here. The documentation at http://demos.krajee.com/widget-details/select2 is not very specific about how to do this.
I don't believe you can do that. Select2 sends the data in post as an array, so you would still need to use implode before saving. What i would do instead is in your model class:
class MyModel extends \yii\db\ActiveRecord {
$public myArrayAttribute;
...
public function beforeSave($insert) {
if (parent::beforeSave($insert)) {
$this->myAttribute = implode(',', $this->myArrayAttribute);
return true;
}
return false;
}
public function afterFind() {
parent::afterFind();
$this->myArrayAttribute = explode(',', $this->myAttribute);
}
}
This way myArrayAttribute will hold the values from the comma separated field as an array. Of course you will need to add validation rules for it and use it instead of your other attribute in create and update forms.
if you're displaying a form with already populated fields, maybe you want to update an already existing object, and you want to display the already saved value for the Select2 field, use 'data' => [ 1 => 'Some value' ], where 1 is the value, associated to the value displayed in the form. You can retrieve stuff to put in data from DB beforehand.
Source: https://github.com/kartik-v/yii2-widget-select2/issues/37
I am trying to assign a placeholder value to a drop down menu that holds state abbreviations from an entity model.
This is the example code I have tried, but that is not working, because
#Html.DropDownListFor(m => m.StateID, new SelectList(Model.States, "ID", "Abbreviations", Model.StateID), new { id = "StateID" + Model.ID, data_placeholder = "State" })
When I open the page, the first value that shows is AL for Alabama instead that the word "State"
You can use this overloaded version of DropDownListFor to specify default option :-
#Html.DropDownListFor(m => m.StateID, new SelectList(Model.States,"ID","Abbreviations"),
"State", new { id = "StateID" + Model.Id })
Also, Please note that there is no need to specify Model.StateID again in SelectList constructor because automatic selection of dropdown (selected value) will be taken care by first param i.e. m => m.StateID.