samedi 9 novembre 2019

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).

problem photo

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire