tinymce / tinymce-blazor

Blazor integration
MIT License
45 stars 13 forks source link

feat: add form validation support #31

Closed rexebin closed 2 years ago

rexebin commented 2 years ago
  1. add form validation support
  2. add support for dotnet 6.0
jscasca commented 2 years ago

Hey @rexebin this looks pretty good. It took me a while since it changed all the formatting of the class but overall looks well done.

One of the reasons I didn't inherited InputBase from the start was the limitation of using elements only inside an EditContext. Looking at it now, I wonder if people actually use it outside an EditForm at all. On the plus side, it could handle the Css changes, validations and easier access to EditContext and FieldIdentifier. The downside would be changing the current Value mechanics to update. I can take a quick look into that and see how it works out

rexebin commented 2 years ago

@jscasca I am sorry for the formatting, I should not have done it. My editor did it automatically and I didn't pay attention when committing. I am not sure how the changes affect current value mechanics, as far as I understand it, the changes only affect ClassName and trigger validations.

jscasca commented 2 years ago

@rexebin changing the current Value mechanics was one of the downsides of using InputBase I was talking about. I'm happy to go with your solution instead of using InputBase. The only things I would change are:

  1. Rename the property For to Field instead (In a validation it makes sense to have "For" the value you are validating but it feels like in an input field makes more sense to name the field)
  2. Change the notify to trigger from OnChangeContent
  3. Revert the formatting
rexebin commented 2 years ago

@jscasca what you mean by "change the notify to trigger from OnChangeContent", do you mean change the JSInvokable method from OnChange to OnChangeContent?

rexebin commented 2 years ago

Ok, I understand what you mean now. In this case, there is no need to hook up to change and input events. Both events will trigger OnChangeContent.

rexebin commented 2 years ago

There is a problem with trigger validation in OnChangeContent: 1. the validation will be triggered at the very beginning when the user has not changed anything. 2. it will trigger on input as well and this may make the Editor's validation behaviour differ from other form components when they trigger validation only on change/lost focus.

rexebin commented 2 years ago

@jscasca To trigger validation only on change or on input, I added two flags. Please review and see if there is another more elegant way to deal with the issue. Thank you!