Additional ways of letting SAPUI5 generate messages? - sapui5

One way of creating validation error messages, in this case from Input's minLength & maxLength ...
<Input
placeholder="Enter name"
valueStateText="Error Text."
value="{
path: '/firstName',
type: 'sap.ui.model.type.String',
constraints: {
minLength: 1,
maxLength: 10
}
}"
/>
..., is to register the control or view beforehand via MessageManager:
sap.ui.getCore().getMessageManager().registerObject(oView, true);
Is there a way of automatically generating constraint specific messages without using MessageManager?
If there isn't a way, how is it usually done? Are all views registered in the Component.js or each view's onInit has a MessageManager section as mentioned above?

You can also enable the automatic message generation in the application descriptor (manifest.json) section /sap.ui5/handleValidation as mentioned in the documentation topic Validation Messages.
{
"sap.ui5": {
"handleValidation": true
}
}
handleValidation
Possible values: true or false (default); used to enable or disable validation handling by the message manager for this component, see Error, Warning, and Info Messages.
Source: Descriptor for Applications, Components, and Libraries (manifest.json)
Demo: https://embed.plnkr.co/L0ADaEBKvexsrrKk

Related

How to access the message from a MessageListItem / Message bubble?

I need to access each message in a twillo agents chat to check if any of them are a link, if so I will render a component.
I tried using
flex.MessageListItem.Bubble.Content.message
but I think I am using it wrong.
To edit a specific component that has some link in the message content you'll need to use Content.add (if you want to add a new component to the message bubble) or Content.replace (to replace the component for another that you'll create). In Both methods, replace and add, you can pass an if property that will receive that logic to add/replace or just render the default component.
Follow an example where I replace a default component with another based on a condition:
flex.TaskInfoPanel.Content.replace(<CallbackComponent key="callback-info-component" manager={manager} />, {
sortOrder: -1,
if: (props) => props.task.attributes.taskType === 'callback',
});
To see what coming in condition props you can simply print it using a console.log, so the if condition returns true, it'll replace or add your component, if returns false, it'll doesn't anything.
Follow some docs that can help you:
Flex 1.0 components
Flex 2.0 components
I hope that it can help you.

React Warning: Unknown prop `valueAsNumber` on <input> tag

I have a component that wraps an <input type=number>.
Here is my JSX:
function InputNumber(props) {
return (<input
type="number"
valueAsNumber={props.value}
onChange={e => props.onChange(e.target.valueAsNumber)}
step={props.step}
/>);
}
This compiles to the following JS:
function InputNumber(props) {
return (React.createElement("input", {type: "number", valueAsNumber: props.value, onChange: function (e) { return props.onChange(e.target.valueAsNumber); }, step: props.step}));
}
React is giving me the following warning:
Warning: Unknown prop valueAsNumber on tag. Remove this prop from the element.
It seems to work fine if I read and write from element.valueAsNumber in the DOM, so why doesn't React know about this property?
To use non-standard attributes on React components without having them stripped, you must follow HTML 5 standard and prefix them with "data-" and don't use camel case. So yours would be:
data-value-as-number={props.value}
As Jeff McCloud said, you are going to use non standard html attributes. Your function may be rewritten like this:
function InputNumber(props) {
return (<input
type="number"
data-valueAsNumber={props.value}
onChange={e => props.onChange(e.target.dataset.valueAsNumber)}
step={props.step}
/>);
}
According to the DOM Elements Doc, valueAsNumber is not a valid attribute. This article also confirms that unsupported attributes are stripped.
React does not yet recognize the attribute you specified. This will likely be fixed in a future version of React. However, React currently strips all unknown attributes, so specifying them in your React app will not cause them to be rendered.
You might want to check out this repo instead:
react-numeric-input
Number input component that can replace the native number input which is not yet very well supported and where it is, it does not have the same appearance across the browsers. Additionally this component offers more flexible options and can be used for any values (differently formatted representations of the internal numeric value).

Getting all inputs with custom attribute in a view

I need to go through all inputs (of different types) which contain a custom attribute in common, like below:
<m:Input value="{building>/shortName}" custom:required="true"/>
...
<m:Input value="{building>/longName}" custom:required="true"/>
So I can do a validation on each one of them.
Some of you can imagine why I'm doing that (sap.m.Input hasn't a required property itself as sap.ui.commons.TextField has).
By pure jQuery, I could get it, but it's definitely my last option to try.
Does anyone know how to get such filtered list of controls?
Another better solution for the same issue is also welcome.
I think adding minLength constraint with String type and listening validation error would be a better approach.
<Input value="{
path : 'building>/shortName',
type : 'sap.ui.model.type.String',
constraints : {
minLength: 1
}
}" />
sap.ui.getCore().attachValidationError(function (oEvent) {
oEvent.getParameter("element").setValueState("Error");
});
Also you can have a look at this sample
https://openui5.hana.ondemand.com/explored.html#/sample/sap.m.sample.InputChecked/preview

Why doesn't simple form with bootstrap generate bootstrap-compatible forms?

I follow the API instructions, but the form behavior doesn't output what it says it should in the example and example source code.
I installed simpleform and bootstrap.
I did rails g simple_form:install --bootstrap
I see that the files have been generated.
Simpleform says to do code for an element like so
= simple_form_for #park, html: { multipart: true, role: "form", class: "form-horizontal" } do |f|
- if #park.errors.any?
#error_explanation
%h2= "#{pluralize(#park.errors.count, "error")} prohibited this park from being saved:"
%ul
- #park.errors.full_messages.each do |msg|
%li= msg
= f.input :address, label: 'address', autofocus: true, placeholder: "123 Fake Street Irvine, CA 90123", class: "form-control"
The layers of DSLs for simple output of forms is getting kind of ridiculous.
Many things wrong with the output
1) the wrapping classes don't match bootstrap's form-group, and instead it's still controls
2) the form doesn't stretch out 100% width like it should.
3) If an input isn't detected as "required", the label doesn't get wrapped, and it sticks off to the left of the screen.
Why isn't the API working?
The simple form generator command with bootstrap generates config initializers files for bootstrap 2.x
Thus you must modify the initializer files to spit out appropriate classes.
See the answer to this question.
Bootstrap3 and simple form

Jquery Validation Basics

I asked a pretty tough question on Jquery Validation earlier on, and nobody seems able to answer it, so I am just going to go for the more basic how-to question...
Say I have a form (MVC2 asp.net form might I add), one textbox, on textbox with DateTime in it and one radio button (the values of the Radio Button are Yes or No). How do I get simple custom validation on those Form Elements if I know the name of the form elements?
Keep in mind these elements are going to be generated Dynamically and so are there validation rules... I am for now just hoping to fudge it a little bit and put permanent validation in there...
I am a complete Jquery and Javascript nooob... All I have ever done with either programming language was add simple tools into my code...
Thank you for your help.
How do I get simple custom validation on those Form Elements if I know the name of the form elements?
The documentation contains many examples of how to setup the plugin. Here's an example with static rules:
$('#myform').validate({
rules: {
Name: {
required: true
},
DateOfBirth: {
required: true,
date: true
},
IsMajor: {
required: true
}
}
});
and if you wanted to dynamically add those rules you could do this:
$('#myform').validate();
and then dynamically add rules to individual form elements:
$('#Name').rules('add', {
required: true
});
$('#DateOfBirth').rules('add', {
required: true,
date: true
});
$('#IsMajor').rules('add', {
required: true
});
You don't need to know the id of the element as long as you assign it to the proper class, e.g. the built-in "required". Set the class and everything else is taken care of.