Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html.form.class.php #30955

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open

html.form.class.php #30955

wants to merge 16 commits into from

Conversation

avadnc
Copy link

@avadnc avadnc commented Sep 13, 2024

NEW|New Functions for Managing Forms and Tables in html.form.class.php

Added new methods for handling forms and tables through the html.form.class.php class, which reduces the amount of code developers need to write to render tables, manage forms, or add input fields.

Long description

This update introduces new functions in the html.form.class.php class to simplify the creation and management of forms and tables in Dolibarr. The goal is to reduce the boilerplate code required for rendering tables, creating forms, or adding inputs, resulting in cleaner and more maintainable code.

New Methods for Forms:

  • openForm($form_name, $action = '', $method = 'POST', array $hiddenoptions = array()): Opens a form with specified name, action, method, and optional hidden input fields.
  • closeForm(): Closes the form by outputting the closing </form> tag.
  • createInputField($name, $value = '', $type = 'text', $class = ''): Creates an input field dynamically with name, value, type (default: text), and optional class attributes.

New Methods for Tables:

  • openTable($class = 'noborder centpercent'): Opens an HTML table with an optional CSS class.
  • closeTable(): Closes the table by outputting the closing </table> tag.
  • addRow($columns = array(), $rowClass = ''): Adds a table row with specified columns, each column accepting content and an optional class. Supports rowspan and colspan.
  • addHeaderRow($headers = array(), $class = 'liste_titre', $rowspan = 1, $colspan = 1): Adds a header row with specified headers, with optional rowspan and colspan support.
  • addColumn($content = '', $class = '', $rowspan = 1, $colspan = 1): Adds a column inside a row with optional rowspan, colspan, and class attributes.

Benefits:

  • Reduced code complexity for developers by abstracting common form and table-related tasks.
  • Improved flexibility in form and table rendering.
  • Support for rowspan, colspan, and individual column classes in tables.

@hregis
Copy link
Contributor

hregis commented Sep 13, 2024

@avadnc great ! maybe to add the possibility to have an "id" in "tr" and "td" for jquery or other ? thanks

@hregis
Copy link
Contributor

hregis commented Sep 13, 2024

@avadnc moreover it would be necessary to be able to have an "id" for each element (table, td, tr, form, etc.) which can potentially be different from "name"

@hregis
Copy link
Contributor

hregis commented Sep 13, 2024

@avadnc and the possibility to add more "attribute"

Copy link
Author

@avadnc avadnc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response to @hregis

Thank you for your valuable suggestions! I have implemented the changes as requested:

  1. ID Support for Elements: Now, id attributes can be assigned to the following elements: <table>, <tr>, <td>, and <th>. This allows for easy DOM manipulation with jQuery or other JavaScript frameworks.

  2. Custom Attributes: I've added support for additional custom attributes on these elements. Developers can now add any HTML attribute, such as data-*, onclick, style, and others, by passing them in an array. This offers more flexibility when rendering tables and forms.

New/Updated Methods:

  • openTable($class = 'noborder centpercent', $id = '', $attributes = array()): Opens a table element with an optional CSS class, ID, and additional attributes.
  • addRow($columns = array(), $rowClass = '', $rowId = '', $attributes = array()): Creates a table row (<tr>) with optional class, ID, and custom attributes. Each column within the row can also have its own set of custom attributes.
  • addHeaderRow($headers = array(), $class = 'liste_titre', $rowspan = 1, $colspan = 1, $id = '', $attributes = array()): Creates a header row (<th>) with optional class, ID, and custom attributes.
  • addColumn($content = '', $class = '', $rowspan = 1, $colspan = 1, $id = '', $attributes = array()): Adds a table column (<td>) with support for optional class, ID, rowspan, colspan, and custom attributes.

Example Usage:

$table = new TableHelper();

// Open table with ID and custom data attribute
print $table->openTable('myClass', 'myTable', array('data-info' => 'exampleTable'));

// Add row with class, ID, and custom attributes on individual columns
print $table->addRow(array(
    array('content' => 'Column 1', 'class' => 'nowrap', 'id' => 'column1', 'attributes' => array('data-column' => 'first')),
    array('content' => 'Column 2', 'class' => 'right nowrap', 'id' => 'column2')
), 'oddeven', 'row1', array('data-row' => 'firstRow'));

// Close the table
print $table->closeTable();

@hregis
Copy link
Contributor

hregis commented Sep 13, 2024

@avadnc thanks, maybe move your functions in a file "html.formhelper.class.php" with a class name "FormHelper" in order to lighten the "html.form.class.php" file? what do you think @eldy ?

Copy link
Author

@avadnc avadnc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much! I look forward to your feedback and will follow any instructions you provide.

…and closing functions, to a new file 'html.formhelper.class.php' and removed them from 'html.form.class.php Dolibarr#30955
Copy link
Author

@avadnc avadnc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hregis: I have now created the html.formhelper.class.php file and moved the functions related to table, row, and column creation, as well as form opening and closing, into that file. These functions have been removed from html.form.class.php as suggested.

@avadnc avadnc changed the title html.form.class.php #30941 html.form.class.php Sep 13, 2024
@avadnc
Copy link
Author

avadnc commented Sep 16, 2024

Hi guys! What else do you need to incorporate this new class into the Dolibarr core?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants