Page 1 of 1

how to prevent adding wrong attribute and wrong value in web author

Posted: Fri Jul 07, 2023 8:33 am
by shikhar_472
Hi Team,

Is there any way by which we can prevent adding the wrong attribute or wrong value to any element.

Thanks,
Shikhar.

Re: how to prevent adding wrong attribute and wrong value in web author

Posted: Fri Jul 07, 2023 9:34 am
by mihaela
Hello,

You can use the AuthorDocumentFilter API, it includes a method called setAttribute that is invoked before setting the value of an attribute in the specified element and you can use it to reject the wrong attribute names or values.

Best Regards,
Mihaela

Re: how to prevent adding wrong attribute and wrong value in web author

Posted: Fri Jul 07, 2023 3:05 pm
by shikhar_472
is there any option.xml configuration in oxygen which will validate according through schema and prevent to add attribute

Re: how to prevent adding wrong attribute and wrong value in web author

Posted: Fri Jul 07, 2023 4:33 pm
by mihaela
Hi,

Can you please detail your use-case? You want the user not be able to insert an invalid attribute or just an attribute value?
For the moment there is no option like this but we can register an issue, depending on your request.

Best Regards,
Mihaela

Re: how to prevent adding wrong attribute and wrong value in web author

Posted: Wed Jul 12, 2023 8:50 am
by shikhar_472
Thanks mihela,

It got worked for me is it possible when attribute is not getting added we can provide error message on UI of web author from right attribute pane saying attribute could not be added, because that UI is not in our control so is there any way to do that quickly

Re: how to prevent adding wrong attribute and wrong value in web author

Posted: Wed Jul 12, 2023 10:39 am
by mihaela
Hello,

There is no way for you to add a message in the Attributes panel from API.
You can use the AuthorDocumentFilter API that I mentioned in a previous message (setAttribute method) and check if the attribute is valid. If it is not you can reject the operation and present a message to the user.

Best Regards,
Mihaela

Re: how to prevent adding wrong attribute and wrong value in web author

Posted: Wed Jul 12, 2023 11:42 am
by shikhar_472
how to present the message to the user from backend is it possible without having the UI control

Re: how to prevent adding wrong attribute and wrong value in web author

Posted: Wed Jul 12, 2023 12:58 pm
by shikhar_472
if (StringUtils.isNotBlank(value.getRawValue()) && validateAttributeAndValue(element, attributeName, value)) {
super.setAttribute(filterBypass, attributeName, value, element);
}else {

}


inside else block i want to throw error if attribute is not get added and that should be visible on UI

Re: how to prevent adding wrong attribute and wrong value in web author

Posted: Wed Jul 12, 2023 1:38 pm
by mihaela
Hello,

You can use the following API to present a warning to the user: ro.sync.exml.workspace.api.WorkspaceUtilities.showWarningMessage(String)

The code should be something like this:

Code: Select all

authorDocumentModel.getAuthorAccess().getWorkspaceAccess().showWarningMessage("Your message");

Best Regards,
Mihaela