Skip to content

WIP: Implementation of data series input form - #113

Open
johdev-ob wants to merge 10 commits into
sahana:devfrom
johdev-ob:med-parameter-input
Open

johdev-ob wants to merge 10 commits into
sahana:devfrom
johdev-ob:med-parameter-input

Conversation

@johdev-ob

Copy link
Copy Markdown
Collaborator

Description

This is the first approach to implement the input form for storing measurements via Data Series Widget. The form loads and groups the parameters. Single parameters can be added to or removed from the form as well as whole groups. There is also a search bar to filter parameters and groups.

Todos

  • Parameters should be loaded via endpoint (still mocked)
  • Submit function

@johdev-ob johdev-ob self-assigned this Sep 21, 2026

@nursix nursix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good start - but could not test-run it due to blocking JS errors (undeclared variables).

Not everything commented on needs to be fixed right away, but I have to hold off the merge until at least the JS blockers are fixed.

* Update the widget options
*/
_init: function() {
self = this;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Undeclared variable self here, this should be const self = this;

You may want to use jshint or similar to catch such issues. Given that this script is in strict mode, this cannot possibly run as-is.

getHtml() {
const parameterElement = $('<li class="dsform-parameter">');

const header = this._renderHeader(data);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You care calling sub-method here with a parameter data, but data is never declared nor initialized here, which will throw immediately.

const $el = $(this.element),
widgetID = $el.attr('id');

window.addEventListener(

@nursix nursix Sep 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This event handler is never removed, so if the widget is instantiated more than once in the page, handlers will accumulate and run repeatedly. It makes therefore sense to add this as a name-spaced event in bindEvents, and remove the entire event name space in unbindEvents - both of which are called during refresh - and have no event handler binding during _init at all.

# FORM(_id = 'test'),
# _class="ds-crud",
# )
return DataSeriesForm().html('dsForm')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We do not use pascal-case in DOM IDs, so this should probably be 'ds-form' instead.

_class='tiny primary button action-btn'
),
FORM(
DIV(_id = "dsform-header"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a hard-coded DOM ID, which is inconsistent with the following line, where you use a DOM ID derived from widget_id. Since any UI widgets shall be designed for multiple instances per page, hard-coded DOM IDs are prone to conflicts, and should not be used.

Alternatively, you can use a CSS class and bind events on that using the widget_id as reference frame, but this may come with performance trade-offs in some cases.

class DataSeriesForm:
def html(self, widget_id):
widget = DIV(
BUTTON('Add measurement',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The button text is not internationalized, nor is it adaptive to the data model. Using T("Add Results") as a generic fallback might be a good idea - but in general, we need to make this use the CRUD strings of the target resource (here: med_analysis).

To do so, of course, you may have to pass in the resource for introspection.


#dsform-items-selected {
border: 1px solid #e0e0e0;
padding: 10px;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remember that you're inside a responsive CSS framework, where element and font-sizes may change per device and view port size/orientation.

This px-based sizing is good enough for a draft, but for production it needs to be validated across screen sizes and possibly changed into pt-based to make it adapt.

padding: 0;
}

#dsform-collection .dsform-button-remove {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note that the DOM IDs are (or should be) a variable, so using them to bind CSS is probably not the best strategy. Good enough for a first draft, but better to use CSS classes right away.

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.

2 participants