how we can make oxygen to give error when user is trying to make changes which will cause validation issue.

Having trouble installing Oxygen? Got a bug to report? Post it all here.
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

how we can make oxygen to give error when user is trying to make changes which will cause validation issue.

Post by SmitaPatil »

Hi Team,
I have one scenario where suppose if user is trying to delete only the tag and if deletion of tag will cause document to be invalid then oxygen should throw error while deleting the tags.
Can you please tell if we have something in oxygen to handle this scenario?

Thanks & Regards,
Smita
cristi_talau
Posts: 495
Joined: Thu Sep 04, 2014 4:22 pm

Re: how we can make oxygen to give error when user is trying to make changes which will cause validation issue.

Post by cristi_talau »

Hello,

In general, there are some scenarios where it makes sense to have a temporarily invalid document. For example, delete a child element to replace it with another one.
In some cases where it is obviously invalid to delete an element, Web Author blocks this by default. For example, you cannot delete the title of a DITA topic.

There are two options for you:
1. Help us reproduce the case in which it is obviously incorrect to delete an element, but Web Author allows you to delete it. After we reproduce the issue we can fix it in Web Author itself.
2. Use an AuthorDocumentFilter to intercept deletions and block them when the document becomes invalid. Note that running a validation for every delete might degrade the editor performance, but you can still identify some common cases and block them. To display an error you can use ca code like below:

Code: Select all

PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage("You cannot delete this element");
Best,
Cristian
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

Re: how we can make oxygen to give error when user is trying to make changes which will cause validation issue.

Post by SmitaPatil »

Hi Cristian,

its not exactly deleting element its about deleting just tag not content inside it.
in below screenshot you can see venue.name inside content.venue element.
image.png
image.png (15.12 KiB) Viewed 781 times
if suppose user is just removing tag i.e unwrapping venue.name then we will have content as shown below which is not valid as per schema as text is coming directly inside content.venue element .
image.png
image.png (13.8 KiB) Viewed 781 times
Also, I can see after some time oxygen is recognizing it and highlighting in red color as shown in below screenshot.
image.png
image.png (13.23 KiB) Viewed 781 times
so just wanted to know can we check it before hand if user is trying to delete just tag or trying unwrap element and which will cause document to be invalid then we should throw error that it may cause text to be out of context.
Please let me know if you have any questions.

Thanks & Regards,
Smita
Attachments
image.png
image.png (13.23 KiB) Viewed 781 times
cristi_talau
Posts: 495
Joined: Thu Sep 04, 2014 4:22 pm

Re: how we can make oxygen to give error when user is trying to make changes which will cause validation issue.

Post by cristi_talau »

Hello,

Thanks for helping us understand the issue. I registered an internal issue for your use-case and I will update this thread when this "unwrap" behavior will be improved.

Meanwhile you can use the following APIs: With the AuthorDocumentFilter API that I recommended before you can only intercept "delete" events and is not useful for "unwrap".

Best,
Cristian
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

Re: how we can make oxygen to give error when user is trying to make changes which will cause validation issue.

Post by SmitaPatil »

Hi Cristian,

I have tried using this method, in case of invalid deletion of tag, but in case of valid unwrap also it is returning false.
public boolean handleDeleteElementTags(AuthorNode nodeToUnwrap,
AuthorAccess authorAccess)
throws InvalidEditException

is this method will only work user use keyboard to make a change.
can you explain below line which you mentioned in previous answer.
to intercept the "unwrap" user action when the user does this using the keyboard.
and to use below method it will take extra operation, first I have to delete the tag and then need to add just a content of that at caretposition and then verify that this fragment is valid or not inside parent element. can you please tell is there any way other than this or if I am missing some way to try.
boolean canInsertDocumentFragments(AuthorDocumentFragment[] fragments,
WhatElementsCanGoHereContext insertionContext,
short validationMode)


Thanks,
Smita
cristi_talau
Posts: 495
Joined: Thu Sep 04, 2014 4:22 pm

Re: how we can make oxygen to give error when user is trying to make changes which will cause validation issue.

Post by cristi_talau »

Hello,

From what you described, it seems you call the "handleDeleteElementTags" method. You should extend the AuthorSchemaAwareEditingHandlerAdapter class, "implement" the handleDeleteElementTags() method, and register you subclass it in your framework.

In the implementation you can just check if the wrapped fragment can be inserted in the parent element (without deleting anything) and if the fragment cannot be inserted, just return true to pretend that you made the deletion yourself and Web Author should not do its default unwrap operation.

Best,
Cristian
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

Re: how we can make oxygen to give error when user is trying to make changes which will cause validation issue.

Post by SmitaPatil »

Hi Cristian,

Thank you. Issue got resolved.

Thanks & Regards,
Smita
cristi_talau
Posts: 495
Joined: Thu Sep 04, 2014 4:22 pm

Re: how we can make oxygen to give error when user is trying to make changes which will cause validation issue.

Post by cristi_talau »

Hello,

We analysed the issue you reported and in general, if the user presses "Backspace" and the document would become invalid as a result of the unwrap, Web Author blocks the unwrap.

I have two questions that would help us fix the issue:
  • In your case, do you unwrap the content by pressing "Backspace"? Or by invoking a dedicated action (e.g. from the context menu)?
  • Can you share a small sample file together with the schema such that we can reproduce the problem on our side? If you want to share them privately, you can use the Technical Support contact form: https://www.oxygenxml.com/techSupport.html
Best,
Cristian
Post Reply