Blazorise RTE validations - validation

I have a rich text editor from blazorise and I am trying to validate the input a user is writing. Specifically to not be empty. I have created a TextEdit invisible component in order to get that message, but it seems that my validation on textedit to not be triggered. I have a fluentvalidations check, and is not a form.
Here is what I am doing:
<FieldLabel>Viber message:</FieldLabel>
<RichTextEdit #ref="rteViberBody"
ContentChanged="#MyCheckRTEMethod"
PlaceHolder="Type your message here..."
ReadOnly="#readOnly"
SubmitOnEnter="false"
Style="height:80px">
<Editor>
</Editor>
<Toolbar>
<RichTextEditToolbarGroup Float="Float.End">
<RichTextEditToolbarButton Action="RichTextEditAction.Bold" />
<RichTextEditToolbarButton Action="RichTextEditAction.Italic" />
<RichTextEditToolbarButton Action="RichTextEditAction.Strike" />
<RichTextEditToolbarButton Action="RichTextEditAction.Image" />
<RichTextEditToolbarButton Action="RichTextEditAction.Clean" />
</RichTextEditToolbarGroup>
</Toolbar>
</RichTextEdit>
</Field>
</Fields>
<Fields>
<Field>
<Validation AsyncValidator="#ValidateRTEViberInputAsync">
<TextEdit #bind-Text="viberMessageHiddenForValidation" #bind-Text:event="oninput" Visibility="Visibility.Invisible">
<Feedback>
<ValidationError>Please type a message.</ValidationError>
</Feedback>
</TextEdit>
</Validation>
</Field>
Has someone has a clue of what needs to be done or change in order to make it work?
Thanks in advance

I've just found that this is proposed: https://github.com/Megabit/Blazorise/issues/1792
So far there's a workaround but not very nice:
<RichTextEdit #ref="richTextEditRef"
ConfigureQuillJsMethod="blazoriseDemo.configureQuillJs"
ContentChanged="#OnContentChanged"
Border="#( string.IsNullOrWhiteSpace( contentAsText ) ? Border.Danger : null)">
...
</RichTextEdit>
#if ( string.IsNullOrWhiteSpace( contentAsText ) )
{
<Paragraph TextColor="TextColor.Danger">Text is empty</Paragraph>
}
else
{
<Paragraph TextColor="TextColor.Success">Text is valid</Paragraph>
}
#code{
private string contentAsText;
public async Task OnContentChanged()
{
contentAsText = await richTextEditRef.GetTextAsync();
}
}

Related

Radzen DataGrid Multiple Selection only filtered Items

I have a Razor Component (.net 6) where I make use of the Radzen DataGrid Multiple Selection.
<RadzenDataGrid
#ref="contactsGrid" Data="#contacts" AllowColumnResize="true" EditMode="DataGridEditMode.Single"
RowUpdate="#OnUpdateRow" RowCreate="#OnCreateRow"
AllowSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
TItem="ContactModel" AllowRowSelectOnRowClick="false" SelectionMode="DataGridSelectionMode.Multiple" #bind-Value=#selectedContacts>
<Columns>
<RadzenDataGridColumn TItem="ContactModel" Width="40px" Sortable="false" Filterable="false">
<HeaderTemplate>
<RadzenCheckBox TriState="false" TValue="bool" Value="#(contacts.Any(i => selectedContacts != null && selectedContacts.Contains(i)))" Change="#(args => selectedContacts = args ? contacts.ToList() : null)" />
</HeaderTemplate>
<Template Context="contacts">
<RadzenCheckBox TriState="false" Value="#(selectedContacts != null && selectedContacts.Contains(contacts))" TValue="bool" Change=#(args => { contactsGrid.SelectRow(contacts); }) />
</Template>
</RadzenDataGridColumn>
<!-- FirstName -->
<RadzenDataGridColumn TItem="ContactModel" Property="FirstName" Title="FirstName">
<EditTemplate Context="contact">
<RadzenTextBox #bind-Value="contact.FirstName" Style="width:100%; display: block" Name="FirstName" />
<RadzenRequiredValidator Text="FirstName is required" Component="FirstName" Popup="true" />
</EditTemplate>
</RadzenDataGridColumn>
<!-- LastName -->
<RadzenDataGridColumn TItem="ContactModel" Property="LastName" Title="LastName">
<EditTemplate Context="contact">
<RadzenTextBox #bind-Value="contact.LastName" Style="width:100%; display: block" Name="LastName" />
<RadzenRequiredValidator Text="LastName is required" Component="LastName" Popup="true" />
</EditTemplate>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
In the HeaderTemplate you can directly select or deselect all items.
Is it possible to change the function so that only all items are selected that match the filter? i.e. which items are currently displayed when I search for certain items using the filter option?
you can use contactsGrid.View to get visible rows. try to use contactsGrid.View instead of selectedContacts.

{nativescript} get value from datepicker and save result to textbox

On my xml, I have 1 textfield and 1 datepicker. How do I get a datepicker result and storing it result on the textfield?
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo">
<StackLayout>
<TextField hint="tanggalprospek" text="{{ tanggalprospek }}" />
<DatePicker day="15" month="5" year="2016" id="date" />
<Button text="Get Tap" tap="{{ getTap }}" />
</StackLayout>
</Page>
Many thanks for your help.. :)
Get the datepicker in the page controller and get the date value of it, then set it to the textfield along with the notifyPropertyChange event. I also use moment.js to have a good date format.
In the xml:
<Button text="Get Tap" tap="getTap" />
In the page controller:
var moment = require("moment");
export function getTap(args) {
var myDatePicker = page.getViewById("date");
var date = moment(myDatePicker.date);
var dateText = date.format("Do MMM [,] H:mm").toString();
page.bindingContext.set("tanggalprospek", dateText);
page.bindingContext.notifyPropertyChange("tanggalprospek", dateText);
}
P/s: I'm using TypeScript

Any way to set editActions on a ListView with dataCollection?

I have a ListView that's hooked to a dataCollection, is it possible to add editActions?
Can't seem to find a way to add these to my ItemTemplate or ListItem.
Here's my (shortened) view:
<ListView id="listViewSpots" defaultItemTemplate="history">
<Templates>
<ItemTemplate name="history" id="itemTemplateHistory" canEdit="true">
<Label bindId="serie" class="serie" />
</ItemTemplate>
</Templates>
<ListSection id="listSectionSpots" dataCollection="spot" dataFilter="listFilter">
<ListItem itemId="{id}" serie:text="{serie}" searchableText="{serie}" />
</ListSection>
</ListView>
You can add custom actions like this:
"ListItem[platform=ios]":{
accessoryType: Titanium.UI.LIST_ACCESSORY_TYPE_DISCLOSURE,
editActions: [{ title: "Add",
style: Ti.UI.iOS.ROW_ACTION_STYLE_DEFAULT },
{ title: "Archive",
style: Ti.UI.iOS.ROW_ACTION_STYLE_DEFAULT },]
}
Editable and EditActions are just regular properties of a ListItem and can be added as such. Through a transform function (dataTransform) you can make this customizable as well
<ListView id="listViewSpots" defaultItemTemplate="history">
<Templates>
<ItemTemplate name="history" id="itemTemplateHistory" canEdit="true">
<Label bindId="serie" class="serie" />
</ItemTemplate>
</Templates>
<ListSection id="listSectionSpots" dataCollection="spot" dataFilter="listFilter">
<ListItem
itemId="{id}"
serie:text="{serie}"
searchableText="{serie}"
editable="{editable}"
editActions="{editActions}"
/>
</ListSection>
</ListView>
This way you can still configure it per ListItem
Yes it is possible.
Can you specify your issue ?
Can you enable slide action?
Do you wanna know how to handle click event?
Maybe this can help you:
"ItemTemplate[platform=ios]":{
canEdit: true
}

Liferay form does not check required fields at Add, despite checking them at Edit

I have a Liferay entity created by Service Builder, with the field "name" described as required in portlet-model-hints.xml:
<model-hints>
<model name="com.example.model.Person">
[...]
<field name="name" type="String">
<validator name="required" />
</field>
[...]
</model>
</model-hints>
Add and Edit are powered by the same JSP edit_person.jsp:
<%#include file="/html/init.jsp"%>
<%
Person person = null;
long personId = ParamUtil.getLong(request, "personId");
if (personId > 0) person = PersonLocalServiceUtil.getPerson(personId);
%>
<aui:model-context bean="<%= person %>" model="<%= Person.class %>" />
<portlet:renderURL var="viewPersonURL" />
<portlet:actionURL name='<%= person == null ? "addPerson" : "updatePerson" %>'
var="editPersonURL" windowState="normal" />
<aui:form action="<%= editPersonURL %>" method="POST" name="fm">
<aui:fieldset>
<aui:input type="hidden" name="personId"
value='<%= person == null ? "" : person.getPersonId() %>'/>
<aui:input name="name" />
</aui:fieldset>
<aui:button-row><aui:button type="submit" /></aui:button-row>
</aui:form>
PROBLEM: When adding a new person, no validation is done, I can enter no name and push submit and the entity is saved with an empty name:
Despite the fact that when editing that person, the name requirement is enforced:
This happens on Firefox but not on Chrome.
This is a bug in Liferay 6.2:
https://issues.liferay.com/browse/LPS-48087
This bug has been fixed in Liferay 7.0.0 M2

Get component parameters return empty value on joomla 3.4.1

I have in my component in admin section my "config.xml", the config inputs are ok on the administration of Joomla.
I have for example a field with "my_custom_test" and I set a value, for example "test". I click on "save" button.
If I'm in a view and I want to get my value I'm writing that
$compo_params = JComponentHelper::getParams('com_xxxxx');
var_dump($compo_params).'<br />';
echo $compo_params->get('my_custom_test', 'EMPTY');
The result is that
object(Joomla\Registry\Registry)#19 (2) { ["data":protected]=> object(stdClass)#20 (1) { ["params"]=> object(stdClass)#57 (1) { ["my_custom_test"]=> string(4) "test" } } ["separator"]=> string(1) "." }
EMPTY
The result is "EMPTY" instead of "test".
Do you have any idea ?
Actually I have found the source of the problem, it is in the component config.xml file. If you have the parameters enclosed in a tag (which was the standard practice for Joomla in the past), then the parameters are stored inside an object called "params", eg
<?xml version="1.0" encoding="utf-8"?>
<config>
<fields name="params" label="Some label">
<fieldset name="basic" label="Basic Options" description="">
<field name="some_option" label="label" type="text" description="" />
</fieldset>
</fields>
</config>
To correct the problem, just leave out the tag:-
<?xml version="1.0" encoding="utf-8"?>
<config>
<fieldset name="basic" label="Basic Options" description="">
<field name="some_option" label="label" type="text" description="" />
</fieldset>
</config>
If you look at any of the core Joomla component config.xml files this is how they do it now.
Then the standard method of getting the component params works:-
$compo_params = JComponentHelper::getParams('com_xxxxx');
$my_custom_test = $compo_params->get('my_custom_test', '');
The solution is
echo $compo_params->get('params')->my_custom_test;

Resources