InputTinyMCEEditor.Blazor
1.0.0
See the version list below for details.
dotnet add package InputTinyMCEEditor.Blazor --version 1.0.0
NuGet\Install-Package InputTinyMCEEditor.Blazor -Version 1.0.0
<PackageReference Include="InputTinyMCEEditor.Blazor" Version="1.0.0" />
paket add InputTinyMCEEditor.Blazor --version 1.0.0
#r "nuget: InputTinyMCEEditor.Blazor, 1.0.0"
// Install InputTinyMCEEditor.Blazor as a Cake Addin #addin nuget:?package=InputTinyMCEEditor.Blazor&version=1.0.0 // Install InputTinyMCEEditor.Blazor as a Cake Tool #tool nuget:?package=InputTinyMCEEditor.Blazor&version=1.0.0
InputTinyEditor
An Input component wrapping TinyMCE Blazor Component, to be used inside an EditForm component. It offers the same validations experience as Blazor’s build-in form components out of the box.
Usage
Once the package is installed, you can use the component straight away. There is no extra JavaScript script to add.
<EditForm OnValidSubmit="@Submit" EditContext="@CurrentEditContext">
<DataAnnotationsValidator />
<p>
<label>Title</label>
<InputText @bind-Value="Model.Title"></InputText>
<ValidationMessage For="() => Model.Title" />
</p>
<p>
<label>Content</label>
<InputTinyMCEEditor.Blazor.InputTinyEditor For="() => Model.Content"
@bind-Value="Model.Content"
Height="300" />
<ValidationMessage For="() => Model.Content" />
</p>
<button class="btn btn-primary" type="submit">Submit</button>
</EditForm>
@code {
public Model Model { get; set; } = new Model();
private EditContext? CurrentEditContext;
protected override void OnInitialized()
{
CurrentEditContext = new(Model);
base.OnInitialized();
}
private void Submit()
{
Console.WriteLine($"Title is {Model.Title}");
Console.WriteLine($"Content is {Model.Content}");
}
}
Required Parameters
Parameter For
of type Expression<Func<string>>
is required to provide identifier for validations
TinyMCE Editor Configurations
InputTinyEditor comes with default configurations, including Non-Premium Plugins and entire menubar and toolbar
Add Configurations via Parameters
InputTinyEditor is extended from the original TinyCME.Blazor.Editor. It inherits and supports all the params from TinyMCE.Blazor.Editor. See more here.
Additional Parameters:
- InputTinyEditor provides the following parameters of type string for quick configuration:
Plugins
,Toolbar
,Menubar
.
<InputTinyMCEEditor.Blazor.InputTinyEditor For="() => Model.Content"
@bind-Value="Model.Content" Height="300" Menubar="file edit view insert format tools table"/>
- Additional configuration can be added through
Conf
parameter
<InputTinyMCEEditor.Blazor.InputTinyEditor For="() => Model.Content"
@bind-Value="Model.Content" Height="300" Conf="AdditionalConf"/>
@code{
private Dictionary<string, object> AdditionalConf = new Dictionary<string, object>
{
{"quickbars_selection_toolbar", "bold italic | quicklink h2 h3 blockquote quickimage quicktable"}
};
}
- You can also add configuration via arbitrary parameters.
<InputTinyMCEEditor.Blazor.InputTinyEditor For="() => Model.Content"
@bind-Value="Model.Content"
quickbars_selection_toolbar="bold italic | quicklink h2 h3 blockquote quickimage quicktable"
/>
- By default InputTinyEditor trigger validation when
onchange
event fires. You can change the trigger tooninput
by specifyingValidateOnInput
totrue
.
<InputTinyMCEEditor.Blazor.InputTinyEditor For="() => Model.Content"
@bind-Value="Model.Content" ValidationOnInput="@true"
/>
Add Configurations via JavaScript Script
- For the configurations that include complex objects or functions, it is easier to add them via a script. By design, InputTinyEditor will look for
window. tinyMceConf
object and append to existing configurations. To add additional configurations, add ascript
tag in theindex.html
or_layout.html
.
<body>
…
<script>
window.tinyMceConf = {
file_picker_callback: function (callback, value, meta) {
/* Provide file and text for the link dialog */
if (meta.filetype === 'file') {
callback('https://www.google.com/logos/google.jpg', { text: 'My text' });
}
/* Provide image and alt text for the image dialog */
if (meta.filetype === 'image') {
callback('https://www.google.com/logos/google.jpg', { alt: 'My alt text' });
}
/* Provide alternative source and posted for the media dialog */
if (meta.filetype === 'media') {
callback('movie.mp4', { source2: 'alt.ogg', poster: 'https://www.google.com/logos/google.jpg' });
}
}
}
</script>
</body>
- To hook up to TinyMCE Editor’s events, create a
window.tinyMceSetup
function that takeseditor
as parameter and add event on theeditor
as below. InputTinyEditor component will append this function to existing setup script. Note,oninput
andonchange
events are used to trigger validations. If you need to add extra behaviours to these two events, you can copy the code from source code and add your code.
<body>
...
<script>
window.tinyMceSetup = (editor) => {
editor.on("init", () => console.log("TinyMCE editor initialized"))
};
</script>
</body>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Components.Web (>= 6.0.0)
- TinyMCE.Blazor (>= 0.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.