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

fix(molgenis-components): null-check for expressions when a field is emptied after being filled #4189

Closed
wants to merge 11 commits into from

Conversation

svandenhoek
Copy link
Contributor

What are the main changes you did:
Fixed a bug where empty value validation was bugged. Once a field is filled, it cannot be put back into its original (value is null) state. Similar to #3933.

Example:

Schermopname.2024-09-05.om.18.54.56.mov

To be more specific, if having a table with 2 columns (c1 & c2), where c2 can only be filled if c1 is empty, different code would give different errors:

c1 == null -> only worked as long as c1 is empty, if filled and emptied again the error message would remain
c1.length === 0 -> only worked AFTER value was set and then emptied, but when trying to save give the error Update into table 'test' failed.: Transaction failed: script failed: TypeError: Cannot read property 'length' of null
c1 == null || c1.length === 0 -> works but ugly

This PR should address the issue above and make <colName> == null always usable. It fixes InputString, InputText, InputEmail, InputHyperlink & InputPassword.

Only InputString was tested manually with validation string in an actual database table. Other ones have e2e tests to see if value is set to null if empty input field.

how to test:

todo:

  • updated docs in case of new feature
  • added/updated tests
  • added/updated testplan to include a test for this fix, including ref to bug using # notation

@svandenhoek svandenhoek changed the title fix(molgenis-components): fixed a bug causing null-check for form expressions to fail fix(molgenis-components): fixed a bug causing null-check for expressions to fail Sep 5, 2024
@svandenhoek svandenhoek changed the title fix(molgenis-components): fixed a bug causing null-check for expressions to fail fix(molgenis-components): null-check for expressions when a field is emptied after being filled Sep 5, 2024
@@ -52,6 +52,10 @@ let props = defineProps({

const emit = defineEmits(["update:modelValue"]);

function updateModelValue(value) {
emit("update:modelValue", value == "" ? null : value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use === instead of ==

@svandenhoek
Copy link
Contributor Author

Included InputSelect from #3933 while processing the feedback.

Copy link

sonarcloud bot commented Oct 7, 2024

@svandenhoek svandenhoek marked this pull request as ready for review October 10, 2024 16:06
Copy link
Contributor

@chinook25 chinook25 left a comment

Choose a reason for hiding this comment

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

see comment

Comment on lines +229 to +233
export function updateModelValue(object, value) {
updateModelValueEmit(object.$emit, value);
}

export function updateModelValueEmit(emit, value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

  • These contain ts errors (implicit any type). Do you have your IDE setup correctly? It should show red lines on these functions.
  • Is it possible to pass this.$emit into the second function? In that case we could remove the first.
  • This comment should not be here, comments double the maintenance of code so should be used only if really necessary.
  • I suggest renaming the function to better reflect what they do e.g. emitModelValueNullSafe

@svandenhoek
Copy link
Contributor Author

This PR is closed in favor of #4353

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