-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
base: develop
Are you sure you want to change the base?
html.form.class.php #30955
Conversation
@avadnc great ! maybe to add the possibility to have an "id" in "tr" and "td" for jquery or other ? thanks |
@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" |
@avadnc and the possibility to add more "attribute" |
There was a problem hiding this 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:
-
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. -
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();
There was a problem hiding this 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
There was a problem hiding this 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.
…per methods to resolve Phan warnings
Hi guys! What else do you need to incorporate this new class into the Dolibarr core? |
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. Supportsrowspan
andcolspan
.addHeaderRow($headers = array(), $class = 'liste_titre', $rowspan = 1, $colspan = 1)
: Adds a header row with specified headers, with optionalrowspan
andcolspan
support.addColumn($content = '', $class = '', $rowspan = 1, $colspan = 1)
: Adds a column inside a row with optionalrowspan
,colspan
, and class attributes.Benefits:
rowspan
,colspan
, and individual column classes in tables.