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

Repeating grp fix #504

Merged
merged 7 commits into from
Oct 29, 2020
Merged

Repeating grp fix #504

merged 7 commits into from
Oct 29, 2020

Conversation

bennsimon
Copy link
Member

@bennsimon bennsimon commented Oct 21, 2020

  • Updates the logic to update the repeating group count object

stepFields.put(repeatingGroupCountObj);
return repeatingGroupCountObj;
} else {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the else block? Is there ever an instance when stepJsonObject is null?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah for malformed json form

Copy link
Contributor

Choose a reason for hiding this comment

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

The method throws JSONException, so I'm thinking malformed JSON will be covered here? The calling method can then figure out how to handle the exception, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is a NPE check.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but when is the stepJsonObject null?

Copy link
Contributor

Choose a reason for hiding this comment

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

either way, you can simply return null without the else block, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, but when is the stepJsonObject null?
When the step does not exist ... for malformed json forms

either way, you can simply return null without the else block, right?
I will still need an if block

Copy link
Contributor

Choose a reason for hiding this comment

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

yea, we can remove the else block though.

//get the generated number of groups
final String generatedGroupsCount = jsonObject.optString(REPEATING_GROUPS_GENERATED_COUNT);
final String generatedGroupsCount = countFieldObject != null ? countFieldObject.optString(VALUE) : "";
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah for malformed json form

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines -331 to -338
referenceEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (!hasFocus) {
addOnDoneAction((TextView) view, doneButton, widgetArgs);
}
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to remove this? This was recommended as a better user experience by Roger onaio/rdt-standard#319 (comment).

Copy link
Member Author

@bennsimon bennsimon Oct 27, 2020

Choose a reason for hiding this comment

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

Yeah, this feature breaks the normal behaviour of repeating group, it adds a bug ... it creates twice the number of groups needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, were you able to figure out why that happens?

Copy link
Member Author

Choose a reason for hiding this comment

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

referenceEditText gains focus when cursor is on it, a number is entered ... then after referenceEditText loses focus when the done button is clicked it fires the addOnDoneAction from focusChange listener at the same time the done button clickListener does the same ... so it generates twice the number of groups.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. Would removing the addOnDoneAction from the done button work then?

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant that since onFocusChanged is triggered when the button is clicked (after entering text) we can simply use onFocusChanged and remove the onclicklistener from the done button.

Copy link
Member Author

Choose a reason for hiding this comment

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

I dont think thats a good idea, looks like a hack ... i think one has to be disabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

It really isn't. The point of the feature (from Roger's comment) is to generate the repeating group when one navigates away from the reference edit text. Clicking on other views (including the done button) counts as navigating away.

Copy link
Member Author

@bennsimon bennsimon Oct 28, 2020

Choose a reason for hiding this comment

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

Why would you need the unclickable done button if you have a onFocusChangeListener on a referenceEditText? I dont get it but anyways ... This needs to be configurable since not all implementation expect that behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

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

tbh, it's only for backward compatibility, we don't need a button any more. The button being "truly" clickable or not doesn't really change the end-user experience so that's not a problem.

You can make it configurable, but any time someone wants both the button and focus change to be supported, the bug will show up again.

@bennsimon bennsimon merged commit dbd4e53 into optimize-native-forms Oct 29, 2020
@bennsimon bennsimon deleted the repeating_grp_fix branch October 29, 2020 14:30
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.

Fix onFocusChange listener feature added on Repeating Group Factory
2 participants