Is there any way to display only info on update screen? - laravel

Here is my update / edit screen on customers area Backpack's admin panel.
ID's field type like text but it just disabled and readonly.
But when i try to save changes, it doesn't work. I think its my primary column and can't changable.
$fields =
[
[ 'name' => 'id', 'label' => 'ID', 'type' => 'text', 'hint' => __('dashboard.crud_listing.customers.hint_of_id'), 'attributes' => ['disabled' => 'disabled', 'readonly' => 'readonly'], 'fake' => true],
];
$this->crud->addFields($fields);
Can anyone have any idea about displaying some data, without saving on this ?

why you setting 'readonly' => 'readonly' inside the 'attributes':
like in doc:
you should set as like:
[ // Text
'name' => 'id',
'label' => "ID",
'type' => 'text',
'readonly' => 'readonly',
],

Related

Can't click on form fields on edit / create of a single controller in laravel on mobile

I have a web application that is using Laravel with the Backpack addon.
Recently i discovered this problem where some fields in the create / edit route in a controller are not selectable in mobile (as if they were readonly). This only happens in mobile (in all browsers) and on this specific controller.
I should also specify that the fields that don't work don't have a reandonly 'style' (darker, grey text). they seem normal, i can't just select them (click on them).
This is part of the form, the fields in the red box are the one that work, the ones outside do not work.
Here is the code in the setup function of the controller:
public function setup()
{
//if (!backpack_user()->hasRole('administrator'))
// abort(403);
/*
|--------------------------------------------------------------------------
| CrudPanel Basic Information
|--------------------------------------------------------------------------
*/
$this->crud->setModel('App\Models\Travel');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/travel');
$this->crud->setEntityNameStrings('travel', 'travels');
$this->crud->setListView('backpack::crud.travel2');
$this->crud->filters();
/*
|--------------------------------------------------------------------------
| CrudPanel Configuration
|--------------------------------------------------------------------------
*/
if ((backpack_user()->hasRole('administrator'))||(backpack_user()->hasRole('superuser'))) //se utente è admin
{
$this->crud->addClause('where','user_id',backpack_user()->id);
// TODO: remove setFromDb() and manually define Fields and Columns
$this->crud->setFromDb();
// add asterisk for fields that are required in TravelRequest
$this->crud->setRequiredFields(StoreRequest::class, 'create');
$this->crud->setRequiredFields(UpdateRequest::class, 'edit');
$this->crud->allowAccess('show');
$this->crud->enableExportButtons();
$this->crud->orderBy('date_start','DESC');
$this->crud->removeColumn('calendar_header');
$this->crud->modifyField('user_id',[
'name' => 'user_id',
'type' => 'hidden',
'value' => backpack_user()->id,
]);
$this->crud->modifyField('calendar_header', [
'name' => 'calendar_header',
'label' => "Intestazione Calendario",
'type' => 'text'
]);
$this->crud->modifyField('client_id', [ // Select2
'label' => "Cliente",
'type' => 'select2',
'name' => 'client_id',
'entity' => 'client',
'attribute' => 'businessname',
'model' => "App\Models\Client",
'placeholder' => 'Seleziona un Cliente',
'options' => (function ($query) {
return $query->orderBy('id', 'ASC')->where('user_id', backpack_user()->id)->get();
}),
]);
$this->crud->modifyField('date_start', [
'name' => 'date_start',
'type' => 'datetime',
'label' => 'Data-Ora di Inizio',
'default' => date("Y-m-d H:i:s"),
'attributes' => [
'required'=>'required',
],
// optional:
/*'datetime_picker_options' => [
'format' => 'DD/MM/YYYY HH:mm',
'language' => 'it'
],*/
]);
$this->crud->modifyField('departure', [
'name' => 'departure', // the db column name (attribute name)
'label' => "Luogo di Partenza", // the human-readable label for it
'type' => 'text' // the kind of column to show
]);
$this->crud->modifyField('destination', [
'name' => 'destination', // the db column name (attribute name)
'label' => "Luogo di destinazione", // the human-readable label for it
'type' => 'text' // the kind of column to show
]);
$this->crud->modifyField('passenger', [
'name' => 'passenger', // the db column name (attribute name)
'label' => "Passeggero", // the human-readable label for it
'type' => 'text' // the kind of column to show
]);
$this->crud->modifyField('passenger_number', [
'name' => 'passenger_number', // the db column name (attribute name)
'label' => "N° di Passeggeri", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('payment_type', [ // select_from_array
'name' => 'payment_type',
'label' => "Tipo Pagamento",
'type' => 'select_from_array',
'options' => ['Fattura' => 'Fattura', 'Carta Di Credito' => 'Carta Di Credito', 'Contanti' => 'Contanti', 'Carte di credito da remoto' => 'Carte di credito da remoto', 'Conto' => 'Conto', 'Paypal' => 'Paypal'],
'allows_null' => true,
'default' => 'one',
// 'allows_multiple' => true, // OPTIONAL; needs you to cast this to array in your model;
]);
$this->crud->modifyField('dare', [
'name' => 'dare', // the db column name (attribute name)
'label' => "Dare €", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('avere', [
'name' => 'avere', // the db column name (attribute name)
'label' => "Avere €", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('driver_id', [ // Select2
'label' => "Autista",
'type' => 'select2',
'attributes' => [
'required'=>'required',
],
'name' => 'driver_id', // the db column for the foreign key
'entity' => 'driver', // the method that defines the relationship in your Model
'attribute' => 'businessname', // foreign key attribute that is shown to user
'model' => "App\Models\Driver", // foreign key model
'placeholder' => 'Seleziona un Autista', // placeholder for the select
'options' => (function ($query) {
return $query->orderBy('id', 'ASC')->where('user_id', backpack_user()->id)->get();
}),
]);
$this->crud->modifyField('car_id', [ // Select2
'label' => "Mezzo",
'type' => 'select2',
'name' => 'car_id', // the db column for the foreign key
'entity' => 'car', // the method that defines the relationship in your Model
'attribute' => 'fullcar', // foreign key attribute that is shown to user
'model' => "App\Models\Car", // foreign key model
'placeholder' => 'Seleziona un Mezzo', // placeholder for the select
'options' => (function ($query) {
return $query->orderBy('id', 'ASC')->where('user_id', backpack_user()->id)->get();
}),
]);
$this->crud->modifyField('service_id', [ // Select2
'label' => "Servizio",
'type' => 'select2',
'name' => 'service_id', // the db column for the foreign key
'entity' => 'service', // the method that defines the relationship in your Model
'attribute' => 'type', // foreign key attribute that is shown to user
'model' => "App\Models\Service", // foreign key model
'placeholder' => 'Seleziona un Servizio', // placeholder for the select
'options' => (function ($query) {
return $query->orderBy('id', 'ASC')->where('user_id', backpack_user()->id)->get();
}),
]);
$this->crud->modifyField('category_id', [ // Select2
'label' => "Tipo Mezzo",
'type' => 'select2',
'name' => 'category_id', // the db column for the foreign key
'entity' => 'category', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => "App\Models\Category", // foreign key model
'placeholder' => 'Seleziona una Categoria', // placeholder for the select
'options' => (function ($query) {
return $query->orderBy('id', 'ASC')->where('user_id', backpack_user()->id)->get();
}),
]);
$this->crud->modifyField('general_notes', [
'name' => 'general_notes', // the db column name (attribute name)
'label' => "Note Generali", // the human-readable label for it
'type' => 'textarea' // the kind of column to show
]);
$this->crud->modifyField('state_booked', [ // Checkbox
'name' => 'state_booked',
'label' => 'Prenotato',
'type' => 'checkbox'
]);
$this->crud->modifyField('state_inprogress', [ // Checkbox
'name' => 'state_inprogress',
'label' => 'In Corso',
'type' => 'checkbox'
]);
$this->crud->modifyField('state_ended', [ // Checkbox
'name' => 'state_ended',
'label' => 'Concluso',
'type' => 'checkbox'
]);
$this->crud->modifyField('state_canceled', [ // Checkbox
'name' => 'state_canceled',
'label' => 'Annullato',
'type' => 'checkbox'
]);
$this->crud->modifyField('state_receipt', [ // Checkbox
'name' => 'state_receipt',
'label' => 'Ricevuta',
'type' => 'checkbox'
]);
$this->crud->modifyField('state_creditcard', [ // Checkbox
'name' => 'state_creditcard',
'label' => 'Carta Di Credito',
'type' => 'checkbox'
]);
$this->crud->modifyField('state_cash', [ // Checkbox
'name' => 'state_cash',
'label' => 'Contanti',
'type' => 'checkbox'
]);
$this->crud->modifyField('state_confirmed', [ // Checkbox
'name' => 'state_confirmed',
'label' => 'Confermato',
'type' => 'checkbox'
]);
$this->crud->modifyField('state_to_confirm', [ // Checkbox
'name' => 'state_to_confirm',
'label' => 'Da Confermare',
'type' => 'checkbox'
]);
$this->crud->modifyField('state_shared', [ // Checkbox
'name' => 'state_shared',
'label' => 'Condiviso',
'type' => 'checkbox'
]);
$this->crud->modifyField('passenger_phonenumber', [
'name' => 'passenger_phonenumber', // the db column name (attribute name)
'label' => "Numero di Telefono Passeggero", // the human-readable label for it
'type' => 'text' // the kind of column to show
]);
$this->crud->modifyField('flight_number', [
'name' => 'flight_number', // the db column name (attribute name)
'label' => "Ind. Volo", // the human-readable label for it
'type' => 'text' // the kind of column to show
]);
$this->crud->modifyField('amount_taxable', [
'name' => 'amount_taxable', // the db column name (attribute name)
'label' => "Imponibile €", // the human-readable label for it
'type' => 'amount_senzaiva', // the kind of column to show
'attributes' => ["step" => "any"]
]);
$this->crud->modifyField('amount', [
'name' => 'amount', // the db column name (attribute name)
'label' => "Importo €", // the human-readable label for it
'type' => 'amount_coniva', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('discount_number', [
'name' => 'discount_number', // the db column name (attribute name)
'label' => "sconto (€)", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('discount_percent', [
'name' => 'discount_percent', // the db column name (attribute name)
'label' => "sconto (%)", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('amount_final', [
'name' => 'amount_final', // the db column name (attribute name)
'label' => "Importo Scontato", // the human-readable label for it
'type' => 'amount_final', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('amount_cash', [
'name' => 'amount_cash', // the db column name (attribute name)
'label' => "Importo Pagamento Diretto", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('end_date', [ // date_picker
'name' => 'end_date',
'type' => 'datetime',
'label' => 'Data-Ora di Fine',
'default' => date("Y-m-d H:i:s"),
// optional:
/*'datetime_picker_options' => [
'format' => 'DD/MM/YYYY HH:mm',
'language' => 'it'
],*/
]);
$this->crud->modifyField('km', [
'name' => 'km', // the db column name (attribute name)
'label' => "Kilometri", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('kmdeparture', [
'name' => 'kmdeparture', // the db column name (attribute name)
'label' => "Kilometri Partenza", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('kmarrival', [
'name' => 'kmarrival', // the db column name (attribute name)
'label' => "Kilometri Arrivo", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('hours', [
'name' => 'hours', // the db column name (attribute name)
'label' => "Ore Totali", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('waiting_hours', [
'name' => 'waiting_hours', // the db column name (attribute name)
'label' => "Ore Totali di attesa", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->modifyField('report_notes', [
'name' => 'report_notes', // the db column name (attribute name)
'label' => "Note sul Report", // the human-readable label for it
'type' => 'textarea' // the kind of column to show
]);
$this->crud->modifyField('invoice_description', [
'name' => 'invoice_description', // the db column name (attribute name)
'label' => "Descrizione Fattura", // the human-readable label for it
'type' => 'textarea' // the kind of column to show
]);
$this->crud->modifyField('sign', [ // image
'label' => "Immagine Cartello",
'name' => "sign",
'type' => 'image',
'upload' => true,
'disk' => 'public'
]);
//***********************************************************
//Rimuovo le colonne che non servono
$this->crud->removeColumn('amount_final');
$this->crud->removeColumn('discount_number');
$this->crud->removeColumn('discount_percent');
$this->crud->removeColumn('km');
$this->crud->removeColumn('hours');
$this->crud->removeField('amount_final');
$this->crud->removeField('discount_number');
$this->crud->removeField('discount_percent');
$this->crud->removeField('km');
$this->crud->removeField('hours');
//***********************************************************
$this->crud->addButtonFromModelFunction('line', 'send_mail', 'sendMail', 'beginning');
$this->crud->addButtonFromModelFunction('line', 'print_doc', 'printDoc', 'beginning');
}
elseif (backpack_user()->hasRole('base')) { //se utente è base
$this->crud->denyAccess(['list', 'create', 'delete']);
$this->crud->setRequiredFields(UpdateRequest::class, 'edit');
$this->crud->addField([
'name' => 'kmdeparture', // the db column name (attribute name)
'label' => "Kilometri alla partenza", // the human-readable label for it
'type' => 'text' // the kind of column to show
],'kmdeparture');
$this->crud->addField([
'name' => 'kmarrival', // the db column name (attribute name)
'label' => "Kilomertri all'arrivo", // the human-readable label for it
'type' => 'text' // the kind of column to show
],'kmarrival');
$this->crud->addField([ // Checkbox
'name' => 'state_canceled',
'label' => 'Annullato',
'type' => 'checkbox'
]);
$this->crud->addField([ // Checkbox
'name' => 'state_confirmed',
'label' => 'Confermato',
'type' => 'checkbox'
]);
$this->crud->addField([ // Checkbox
'name' => 'state_to_confirm',
'label' => 'Da Confermare',
'type' => 'checkbox'
]);
$this->crud->addField([ // date_picker
'name' => 'end_date',
'type' => 'datetime',
'label' => 'Data-Ora di Fine',
'default' => date("Y-m-d H:i:s"),
// optional:
/*'datetime_picker_options' => [
'format' => 'DD/MM/YYYY HH:mm',
'language' => 'it'
],*/
]);
$this->crud->addField([
'name' => 'waiting_hours', // the db column name (attribute name)
'label' => "Ore Totali di attesa", // the human-readable label for it
'type' => 'number', // the kind of column to show
'attributes' => ["step" => "any"],
]);
$this->crud->addField([
'name' => 'report_notes', // the db column name (attribute name)
'label' => "Note sul Report", // the human-readable label for it
'type' => 'textarea' // the kind of column to show
]);
}
}
I already tried removing $this->crud->setFromDb(); and set the columns and fields manually with $this->crud->addColumn and $this->crud->addField but nothing changes.
I am pretty new to backpack and outside that i don't really know what to do.
I am using backpack 3.5 and laravel 5.7.26
**note that i omitted all the modifyColumn from the code
!!! IMPORTANT UPDATE
I tried to comment out random portions of code and apparently is the:
this->crud->modifyField('sign', [ // image
'label' => "Immagine Cartello",
'name' => "sign",
'type' => 'image',
'upload' => true,
'disk' => 'public'
]);
that causes the problem, still i don't understand the reason

How to increase text area size of summnote field in laravel backpack

I am using laravel backpack as a crud and i'm creating a laravel admin panel with it. I need to use the summernote wysiwyg field and there is a options field attribute with laravel backpack and I am trying to input the minheight option for summer note however it does not add it to the intiatlaztion properly
$this->crud->addField([
'name' => 'desc',
'type' => 'summernote',
'label' => "feature description",
'options' => [
'minheight: 300'
]
]);
as you can see it does not increase the mineheight does anyone have any ideas?
i have a work around but it requires me to edit vendor files which it not something i want to have to deal with.
Place this script below your page to modify size and other characteristics of summernote editor:
<script type="text/javascript">
$(document).ready(function() {
$('#summernote').summernote({
height: 250,
disableResizeEditor: true // This is optional if you want to remove resize
});
});
</script>
Place your rows and cols size in the attributes array !
$this->crud->addField([
'name' => 'desc',
'type' => 'textarea',
'label' => "feature description",
'attributes' => [
'rows' => 20,
'cols' => 20
]
]);
You wrote your options property wrong.
'options' => [
'minheight: 300'
]
While actually it should be:
'options' => [
'minheight' => 300
]
See the difference?
You can use summernote API like this:
$this->crud->addField([
'name' => 'desc',
'type' => 'summernote',
'label' => "feature description",
'options' => [
'minheight' => 300,
'height' => 400
]
]);
$this->crud->addField([
// Summernote
'name' => 'description',
'label' => 'Описание',
'type' => 'summernote',
'options' => [
'placeholder'=> 'Содержание статьи',
'height'=> 500,
'toolbar'=>[
['style', ['style']],
['font', ['bold']], // show only bold button
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['insert', ['link', 'picture', 'video']],
['view', ['fullscreen', 'codeview', 'help']]
],
]
]);

How can I add custom dropdown product attribute with options and their positions programmatically?

Like in subject I would like to add custom dropdown product attribute with options and their positions programmatically so I will be able to achieve list like in attached image.
You can use like following in your installer script.
$installer->addAttribute('catalog_product', "shirt_size", array(
'type' => 'int',
'input' => 'select',
'label' => 'Size',
'source' => '',
'sort_order' => 1000,
'required' => false,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'backend' => 'eav/entity_attribute_backend_array',
'option' => array (
'values' => array(
0 => 'Small',
1 => 'Medium',
2 => 'Large',
)
),
));

Display Action labes in single row instead of combobox in grid on admin side magento

I want to show Display Action labes in single row instead of combobox in grid on admin side magento .My code for combobox is
$this->addColumn('action',
array(
'header' => Mage::helper('mymodule')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('mymodule')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
),
array(
'caption' => Mage::helper('mymodule')->__('Delete'),
'url' => array('base'=> '*/*/delete'),
'confirm' => Mage::helper('mymodule')->__('Are you sure?'),
'field' => 'id'
),
array(
'caption' => Mage::helper('mymodule')->__('View'),
'url' => array('base'=> '*/*/view'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
See image for combobox style.
Checkout this code
$this->addColumn('actions', array(
'header' => Mage::helper('adminnotification')->__('Actions'),
'width' => '250px',
'sortable' => false,
'renderer' => 'adminhtml/notification_grid_renderer_actions',
));
under class Mage_Adminhtml_Block_Notification_Grid
and also see the class Mage_Adminhtml_Block_Notification_Grid_Renderer_Actions
If you have still any problem let me know.

How to change comments data with onchange function in addfield in magento

I created custom module and now from admin side on edit form i added extra field select type.
I want to change comments with onchange function for this specific field.See below my code.
$eventElem = $fieldset->addField('banner_type', 'select', array(
'label' => Mage::helper('multibanners')->__('Banner Style'),
'required' => false,
'onchange' => 'checkSelectedItem(this.value)',
'name' => 'banner_type',
'values' => array(
array(
'value' => 'Banner 1',
'label' => 'AnySlider',
),
array(
'value' => 'Banner 2',
'label' => 'Content Slider',
),
));
$eventElem->setAfterElementHtml("<script type=\"text/javascript\">function checkSelectedItem(selectElement){}</script>");
This is my code i alert the value and i got my value but it cannot show it in comments area .Did someone one know how to fix it ?
Thanks
This will update the comment (onchange) with the current selected option
$fieldset->addField('banner_type', 'select', array(
'label' => Mage::helper('multibanners')->__('Banner Style'),
'required' => false,
'onchange' => 'checkSelectedItem(this.value)',
'name' => 'banner_type',
'values' => array(
array(
'value' => 'Banner 1',
'label' => 'AnySlider',
),
array(
'value' => 'Banner 2',
'label' => 'Content Slider',
),
)
))->setAfterElementHtml("<small id='banner_type_comment'>Comments</small>
<script type=\"text/javascript\">
function checkSelectedItem(selectElement){
$('banner_type_comment').update($('banner_type')[$('banner_type').selectedIndex].text);
}
</script>");

Resources