vendredi 12 mai 2023

When i select the `select all` checkbox the each checkbox is not selected visually, but i can see that are selected in the state

I am writing react and i have a Table component in ant design and i want to select all the records that exists in all pages and not in every page that is the default. My code is like this

<Table
   style=
   rowSelection={SelectionConfig}
   ......


 const {selectedRows} = this.state

 const SelectionConfig = {
  selectedRows,
    onSelect: (record, selected, selectedRows, nativeEvent) => {
        this.setState({selectedRows: selectedRows})
        this.props.updateFieldsToCreate(selectedRows)
  },
  columnTitle: () => {
    return(
      <div>
      <Checkbox
        checked={selectedRows.length}
        indeterminate={
          selectedRows.length > 0 &&
          selectedRows.length < this.state.polygonData.length
        }
        onChange={(e) => {
          const { checked } = e.target;
          const selectedRows = checked
            ? this.state.polygonData.map((r) => r)
            : [];
          this.setState({ selectedRows: selectedRows }, () => {
            this.props.updateFieldsToCreate(selectedRows);
          });
        }}
      />
      </div>
    )
  },
  type: "checkbox",
  fixed: true,
}

When i console.log my stateselectedRows i can see that has data and i can sent this data to my server. But the each row seems that it is not selected only visually like this. I have find this it's help me to find how to choose all the data. How i can make this visual so the user can know that has select all the rows in every page.




Sanitize multiple checkbox in Wordpress form

I'm creating Wordpress Plugin and i'm stuck with my checkbox's group. I want to sanitize it but when i add the sanitize_callback, my form do not save anything.

Here's my checkbox part

    function customPostTypeHTML() { 
            
        $args=array(
            'public'                => true,
            'exclude_from_search'   => false,
            '_builtin'              => false
        ); 
        
        $output = 'names';
        $operator = 'and'; 
        $post_types = get_post_types($args,$output,$operator);
        
        foreach ($post_types  as $post_type ) {
            
            <div>
                <input type="checkbox" name="asmsl_custom_post_type_page[<?php echo $post_type; ?>]" id="<?php echo $post_type; ?>" value="1" <?php checked(isset(get_option('asmsl_custom_post_type_page')[$post_type]), '1'); ?>>
                <label for="<?php echo $post_type; ?>"><?php echo ucfirst($post_type); ?></label> 
            </div>
        <?php }
        
    ?>
<?php }

Well, this checkbox is the pre-made wordpress form works well. I test it in a custom form, it works too.

In this example as I said, i use the wordpress form, so i add et register some settings to display it :

    add_settings_section('asmsl-custom-post-type_first_section',  esc_html__('Custom Post Type', 'asmsl_domain'), array($this, 'customPostTypeSection'), 'asmsl-custom-post-type');
    register_setting('customPostTypePage', 'asmsl_custom_post_type_page', array('sanitize_callback' => array($this, 'sanitizeCustomPostType'), 'default' => "0"));
    add_settings_field('asmsl_custom_post_type_page', esc_html__('Choose where to display your Social media', 'asmsl_domain'), array($this, 'customPostTypeHTML'), 'asmsl-custom-post-type', 'asmsl-custom-post-type_first_section');

Problem appears when i use the "array('sanitize_callback')". If I delete this part, my checkboxes are saving well..but I need to sanitize this checkboxes.

I tried many things, doing my own sanitize function but everytime I failed either : not saving data, or : saving data without sanitize anything.

Any suggestions ?




jeudi 11 mai 2023

JqGrid prevent checkboxes from double clic event

I'm using a JqGrid with multiselect : true and i'm using double clic event to launch an edit function.

ondblClickRow: function (rowid) {
                var rowData = $(this).getRowData(rowid);
                document.location.href = "../record/" + rowData['id']
            },

But when it comes to select multiple rows, if you select or deselect the checkbox too quickly it launches the edit function (which I do not want).

How can prevent the dblclick event on the checkboxes and allow it anywhere else on the rest of the row ?




jquery checkbox select and alert popup [duplicate]

I want to show the row specifically when the checkbox corresponding to it is selected

//checkbox
'columnDefs': [{
  'targets': 0,
  'checkboxes': {
    'selectRow': true
  },
  'render': function(data, type, row, meta) {
    data = '<input type="checkbox" class="dt-checkboxes">'
    if (row[3] === 'London') {
      data = JSON.stringify(data);
      return type === 'display' && data.length > 120 ? data.substr(0, 120) + '…' : data;
      // return JSON.stringify(data);
    }
  },
  'createdCell': function(td, cellData, rowData, row, col) {
    if (rowData[3] === 'London') {
      this.api().cell(td).checkboxes.disable();
    }
  }
}],
//checkbox end
columns: [
    {
      title: 'Select',
      data: 'select',
      "width": "12%"
    },

    {
      title: 'Date Time',
      data: 'dateTime',
      "width": "12%"
    },
    {
      title: 'Transaction Id',
      data: 'transactionId',
      "width": "12%"
    },
    {
      title: 'Service Name',
      data: 'serviceName',
      "width": "12%"
    },
    {
      title: 'Status',
      data: 'serviceName',
      "width": "12%"
    },
    {
      title: 'Request',
      data: 'request',
      "width": "22%"
    },
    {
      title: 'Response',
      data: 'response',
      "width": "42%",
      render: function(data, type) {
        data = JSON.stringify(data);
        return type === 'display' && data.length > 120 ? data.substr(0, 120) + '…' : data;
        // return JSON.stringify(data);
      }
    }
  ],

  "language": {
    "emptyTable": "Exception details not found"
  }, select: {
    style: 'os',
    selector: 'td:first-child'
  }

});



mercredi 10 mai 2023

Checkbox with text in same line using ITextSharp

I'm using ITextSharp.LGPLv2.Core 3.3.5 to generate a PDF. I need to create a checkbox with a label. The checkbox can be checked or not depends on the data when I generate the PDF.

Basically something like this:

enter image description here

How can I achieve this? Currently I'm having two problems. First I don't know how to place content in the same line (I'm using a PdfPTable for this but the relative width makes hard to predict the result). Second, I don't know how to create the actuall checkbox. How can I achieve this?




mardi 9 mai 2023

node.js handlebars express how to re-route on checkbox checked or unchecked

I am new to node.js and handelbars. I have searched everywhere and can't find a solution / example on how to re-route? (CRUD) when I check the checkbox.

i.e.

list.hbs snippet below

<label class="toggle">
   <input class="toggle-checkbox" type="checkbox" id="hide">
   <div class="toggle-switch"></div>
   <span class="toggle-label">Show all</span>           
</label>

When checkbox is checked

//list only active bookings for this vehicle
bookings.get('/activeonly/:ID', isLoggedIn, async(req, res) => {    
    const { ID } = req.params;
    const bookings = await pool.query('SELECT * FROM booking WHERE status <> "COMPLETED" and regnr = ?', [ID]);
    const bookingregnr = [ID];
    res.render('bookings/bookingslist', {bookings: bookings, bookingregnr});
    selectedRegnr = bookingregnr;
});

When check box is not checked

//list all bookings for this vehicle
bookings.get('/:ID', isLoggedIn, async(req, res) => {   
    const { ID } = req.params;
    const bookings = await pool.query('SELECT * FROM booking WHERE regnr = ?', [ID]);
    const bookingregnr = [ID];
    res.render('bookings/bookingslist', {bookings: bookings, bookingregnr});
    selectedRegnr = bookingregnr;
});

PLEASE HELP and THANK YOU

I have added the script below and can't move on from here other than out put on the console

    <script  type = "text/javascript">
        const toggles = document.querySelector("#hide");
        toggles.addEventListener('change',function(e){      
            if (toggles.checked){
                 console.log("Show completed");     
                
            }else{
                console.log("Hide completed");
                
            }
        });
    </script>



Flutter pdf package checkbox

I created a pdf document in my flutter project. but the checkbox won't show up. The row has space in front of the text, but it is blank, no checkbox or anything. This happened after I updated the pdf package dependency and starting from there the checkbox won't show up. At first, before I update the package, the checkbox shows up but the checkbox doesn't have a mark even if I set the value to true, the exported pdf only has box but not highlighted, I tried going back to the package version before I update it where it at least shows the checkbox, but any other version is the same, the checkbox did not show up ever again. What could be the cause?

Here is the class where I have the creation of pdf:

// ignore_for_file: prefer_interpolation_to_compose_strings

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:open_file/open_file.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:provider/provider.dart';
import 'package:qvin/utils/labelFormat.dart';

import '../../providers/dvirProvider.dart';

class PdfApi {
  static Future<File> generatePDF(
      BuildContext context,
      String? vehicleNo,
      String? remarks,
      bool isCondition,
      bool isAbove,
      bool isAboveDefect,
      bool isNoResult) async {
    final pdf = pw.Document();
    final font = await rootBundle.load("assets/hind.ttf");
    final ttf = pw.Font.ttf(font);

    DateTime dateToday = DateTime.now();
    final provider = Provider.of<DVIRProvider>(context, listen: false);
    final datasTruck = provider.checklistTruck;
    final datasTrailer = provider.checklistTrailer;

    final headers = [
      'TITLE',
      'STATUS',
    ];

    final dataTruck = datasTruck
        .map((e) => [
              e.title,
              e.isCheck == true ? 'x' : '/',
            ])
        .toList();

    final dataTrailer = datasTrailer
        .map((e) => [
              e.title,
              e.isCheck == true ? 'x' : '/',
            ])
        .toList();

    pdf.addPage(
      pw.MultiPage(
        theme: pw.ThemeData(defaultTextStyle: pw.TextStyle(font: ttf)),
        build: (context) => <pw.Widget>[
          pw.Center(
            child: pw.Text(
              "Driver's Vehicle Inspection Report",
              style: pw.TextStyle(fontSize: 24, fontWeight: pw.FontWeight.bold),
            ),
          ),
          pw.SizedBox(height: 0.8 * PdfPageFormat.cm),
          pw.Center(
            child: pw.Text(
              "Check ANY Defective Item and Give Details under 'Remarks.'",
              style: const pw.TextStyle(
                fontSize: 14,
              ),
            ),
          ),
          pw.SizedBox(height: 2 * PdfPageFormat.cm),
          pw.Column(crossAxisAlignment: pw.CrossAxisAlignment.start, children: [
            pw.Text(
              "DATE: ${LabelFormat.formatDate(dateToday)}",
              style: pw.TextStyle(fontSize: 12, fontWeight: pw.FontWeight.bold),
            ),
            pw.SizedBox(height: 0.5 * PdfPageFormat.cm),
            pw.Text(
              "TRUCK/TRACTOR NO. $vehicleNo",
              style: pw.TextStyle(fontSize: 12, fontWeight: pw.FontWeight.bold),
            ),
            pw.SizedBox(height: 0.5 * PdfPageFormat.cm),
          ]),
          pw.Table.fromTextArray(
            data: dataTruck,
            headers: headers,
            cellHeight: 30,
            headerStyle: pw.TextStyle(fontWeight: pw.FontWeight.bold),
            cellAlignments: {
              0: pw.Alignment.centerLeft,
              1: pw.Alignment.center,
            },
          ),
          pw.Column(crossAxisAlignment: pw.CrossAxisAlignment.start, children: [
            pw.Text(
              "TRAILER(S) NO (S). $vehicleNo",
              style: pw.TextStyle(fontSize: 12, fontWeight: pw.FontWeight.bold),
            ),
            pw.SizedBox(height: 0.5 * PdfPageFormat.cm),
          ]),
          pw.Table.fromTextArray(
            data: dataTrailer,
            headers: headers,
            cellHeight: 30,
            headerStyle: pw.TextStyle(fontWeight: pw.FontWeight.bold),
            cellAlignments: {
              0: pw.Alignment.centerLeft,
              1: pw.Alignment.center,
            },
          ),
          pw.SizedBox(height: 0.8 * PdfPageFormat.cm),
          pw.Text(
            "REMARKS: ${remarks ?? '--'}",
            style: pw.TextStyle(
              fontSize: 12,
              fontWeight: pw.FontWeight.bold,
            ),
          ),
          pw.SizedBox(height: 0.8 * PdfPageFormat.cm),
          if (isNoResult == true)
            pw.Column(children: [
              pw.Row(children: [
                pw.Checkbox(
                  name: 'condition',
                  value: isCondition,
                ),
                pw.SizedBox(width: 0.8 * PdfPageFormat.cm),
                pw.Text(
                  'Condition of the above vehicle is satisfactory',
                  style: const pw.TextStyle(
                    fontSize: 14,
                  ),
                ),
              ]),
              pw.SizedBox(height: 0.8 * PdfPageFormat.cm),
              pw.Row(children: [
                pw.Text(
                  "Driver's Signature",
                  style: const pw.TextStyle(
                    fontSize: 14,
                  ),
                ),
                pw.Spacer(),
                pw.Text(
                  'Date: ${LabelFormat.formatDate(dateToday)}',
                  style: const pw.TextStyle(
                    fontSize: 14,
                  ),
                ),
              ]),
              pw.SizedBox(height: 0.8 * PdfPageFormat.cm),
            ])
          else
            pw.Column(children: [
              pw.Row(children: [
                pw.Checkbox(
                  name: 'aboveDefectsCorrected',
                  value: true,
                ),
                pw.SizedBox(width: 0.8 * PdfPageFormat.cm),
                pw.Text(
                  'Above Defects Corrected',
                  style: const pw.TextStyle(
                    fontSize: 14,
                  ),
                ),
                pw.Checkbox(
                  height: 20,
                  width: 20,
                  name: 'sample',
                  value: true,
                  tristate: true,
                  decoration: pw.BoxDecoration(
                    color: PdfColors.blue,
                  ),
                ),
              ]),
              pw.SizedBox(height: 0.8 * PdfPageFormat.cm),
              pw.Row(children: [
                pw.Checkbox(
                  name: 'aboveDefectsNeed',
                  value: true,
                ),
                pw.SizedBox(width: 0.8 * PdfPageFormat.cm),
                pw.Text(
                  'Above Defects Need NOT Be Corrected For Safe Operation Of Vehicle',
                  style: const pw.TextStyle(
                    fontSize: 14,
                  ),
                ),
              ]),
              pw.SizedBox(height: 0.8 * PdfPageFormat.cm),
              pw.Row(children: [
                pw.Text(
                  "Mechanic's Signature",
                  style: const pw.TextStyle(
                    fontSize: 14,
                  ),
                ),
                pw.Spacer(),
                pw.Text(
                  'Date: ${LabelFormat.formatDate(dateToday)}',
                  style: const pw.TextStyle(
                    fontSize: 14,
                  ),
                ),
              ]),
              pw.SizedBox(height: 0.4 * PdfPageFormat.cm),
              pw.Row(children: [
                pw.Text(
                  "Driver's Signature",
                  style: const pw.TextStyle(
                    fontSize: 14,
                  ),
                ),
                pw.Spacer(),
                pw.Text(
                  'Date: ${LabelFormat.formatDate(dateToday)}',
                  style: const pw.TextStyle(
                    fontSize: 14,
                  ),
                ),
              ]),
            ]),
        ],
      ),
    );
    return saveDocument(name: 'sample.pdf', pdf: pdf);
  }

  static Future<File> getDocument({
    required String name,
    required pw.Document pdf,
  }) async {
    final bytes = await pdf.save();
    final dir = await getApplicationSupportDirectory();
    final file = File('${dir.path}/$name');
    await file.writeAsBytes(bytes);
    print({'file:$file'});
    return file;
  }

  static Future<File> saveDocument({
    required String name,
    required pw.Document pdf,
  }) async {
    final bytes = await pdf.save();
    final directory = await getApplicationDocumentsDirectory();
    final dvirDirectory = Directory('/storage/emulated/0/dvir documents');
    await dvirDirectory.create(recursive: true);
    final file = File('${dvirDirectory.path}/$name');
    await file.writeAsBytes(bytes);
    print('file saved to: ${file.path}');
    return file;
  }

  static Future openFIle(File file) async {
    final url = file.path;
    await OpenFile.open(url);
  }
}