Property Binding: How to Concatenate String Literals and Binding Value - sapui5

I have a StandardItemList in UI5 like this
new sap.m.StandardListItem({
title: "{BOM/#text}",
description: "Version: " + "{REVISION/#text}"
})
How can I achieve getting the description like "Version: ValueOfTheVersion"?
When I delete the word "Version" in the description it works very well.

To enable complex binding syntax, the recommended way is to add the bootstrap configuration option compatVersion with the value "edge". E.g. in index.html:
data-sap-ui-compatversion="edge"
This replaces the need for sap-ui-xx-bindingSyntax since "edge" sets the binding syntax automatically to "complex". Adding bindingSyntax makes only sense if the compatVersion is lower than "1.28". Options with xx should be avoided anyway because they're experimental.
With the complex binding syntax enabled, we can make use of
sap.ui.model.CompositeBinding which includes Expression Binding
as well as plain "{path: '...'}" syntax in XML UI definitions (views or fragments).

Thanks to Rahul!
Adding
data-sap-ui-xx-bindingSyntax="complex"
to the bootstrap in your index.html will do the trick
Full Solution
<script src="/sapui5/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-libs="sap.m,sap.ui.layout,sap.ui.commons,sap.ui.table"
data-sap-ui-theme="sap_bluecrystal">
</script>

Related

How can I include content of a component in Fabricator Assemble *without* a corresponding attribute, or at block level?

In Fabricator Assemble, I could have a component button.html:
<a class="button">{{text}}</a>
I can use this with the syntax {{>button text='Home'}}. Notably, I have to specify a name for the "text" attribute.
I'm looking to see how I can handle not needing to do that in Assemble. The Literals section of the docs for Handlebars (whiich Fabricator Assemble is built on) highlights an alternative syntax with which I could include a button:
{{>button 'Home'}}
In this example, "Home" is a value without any name for it at all. Handlebars also indicates the following is possible as a basic block:
{{#button}}
<b>Some button content</b>
{{/button}}
Likewise, that content has no name.
I'd like to be able to do this same thing in Fabricator Assemble, but it doesn't seem to have a way for me to include this nameless content. In templates there's {% body %} but that doesn't work here.
In Handlebars, which Fabricator Assemble is based on, all examples for how to recreate this involve JavaScript, which doesn't translate well to Assemble.
What can I do to use {{>button 'Some text'}} or {{#button}}...{{/button}} syntax in Fabricator Assemble? Is this behaviour even available?
In the current version, the easiest way to achieve this is with a custom helper.
Add the following to the helpers option in your gulpfile.js:
default: (value, defaultValue) => {
return value || defaultValue;
},
Then inside a handlebars template:
<div>
{{default varName 'default value'}}
</div>

sap.m.Input allow only positive integer values

I need reject for sap.m.Input control any input except integer values. So in input may be inputted only 0-9, without any sign symbol(+-) or any decimal separators. I Can't find good solution. View declared in XML format, and preferable way is just change this XML with additional parameters, if it possible.
Possible solutions:
The first one - write custom formatter.
The second one - try to find some standard solution with types. I found internal data types and they settings, but it seems that they not working well.
A custom formatter won't help you in this case as its only used oneway (model->view).
But data types are your friend here. I would suggest sap.ui.model.type.Integer with a minimum constraint of 0.
<Input value="{path: '/value', type: 'sap.ui.model.type.Integer', constraints:{minimum:0}}" />
However this does have two prerequisites:
You need to enable complex databinding. This can be done in the bootstrap tag in index.html with the data-sap-ui-compatVersion attribute. Version 1.26 is needed at least. You can use the value edge to specify the newest version:
<script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m"
data-sap-ui-compatVersion="edge">
Alternatively you can use data-sap-ui-bindingSyntax="complex".
If the user enters invalid data the datatype throws a ValidationException. The error will be silently ignored but the model won't be updated. To get some feedback for the user you can register the control or the whole view at the MessageManager:
sap.ui.getCore().getMessageManager().registerObject(this.getView(), true);
You can also enable handleValidation in the Component or when instantiating the component.
Example on JSBin.
Regex is your friend here.
Here is a pretty simple jsbin I re-used from someone validating text only and modified the regex to accept numbers only.
You could wire the validation into the change event so it would fire and set the state to error if text entered.
Let us know how this works out.
Cheers,
Nigel

Use same variable name as inherited block name in Mako?

I've stumbled upon a problem with inheritence in Mako. I'll try to illustrate the problem below using two template files...
base.tpl - has a named block title:
<title><%block name="title"></%block></title>
foo.tpl - inherits from base.tpl and sets the title:
<%inherit file="base.tpl" />
<%block name="title">${title}</%block>
The template is rendered (using Bottle) with:
...
return mako_template('foo', title="My title")
Now I expected the output to be
<title>My title</title>
but instead it becomes:
<title><function render_title.<locals>.title at 0x0346A1E0></title>
Any clues? Using a different variable name than the block works.. but I'd like to use the same if possible!
Using this instead works:
<%block name="title">${context["title"]}</%block>
Does anyone know why?

Getting the emberjs starter-kit to work with coffeescript

i'm trying to get the starter-kit example of ember.js to work directly with an app written in coffeescript (with the use of http://coffeescript.org/extras/coffee-script.js).
I want to use this in an development environment, without the need to convert the coffescript to javascript first (manually or with tools like jitter).
Basically i just replaced the line
<script src="js/app.js"></script>
with the lines
<script src="js/libs/coffee-script-1.3.3.min.js"></script>
<script type="text/coffeescript" src="coffee/app.coffee"></script>
in the index.html
All changes i've made can be found in my fork on github at https://github.com/GordonSchmidt/starter-kit
The coffescript itself seems to be fine, because when i convert it to javascript first the starter-kit application works with this javascript. But when i use the coffeescript directly it throws the error "assertion failed: Unable to find view at path 'App.MyView'" in line 45 of ember-0.9.8.1.js. The coffee-script.js all by itself seems to work as well (see demo.html). So it has to be a conflict between ember.js and coffee-script.js.
But I'm not able to find this error. Can someone please point me in the right direction?
from coffeescript.org
The usual caveats about CoffeeScript apply — your inline scripts will
run within a closure wrapper, so if you want to expose global
variables or functions, attach them to the window object.
your coffeescript should look something like this:
<script type="text/coffeescript">
window.App = App = Em.Application.create()
App.MyView = Em.View.extend(
mouseDown: -> window.alert "hello world!"
)​
</script>
see here for a fiddle

J is null in TinyMce.js

I use tinymce on my website and I always run into this annoying j is null.
In my template file I originally had the init method out in the open like in the example...
<script type="text/javascript" >
tinyMCE.init({
mode : "textareas",
theme : "simple"
});
</script>
But in the error console of Firefox I see something that says "j is null" and the reference is somewhere within the tiny_mce.js file.
Any help is appreciated. Thanks so much.
It's a tinymce bug. Internally, the tinymce code uses a <span id="mce_marker"></span> to remember the caret-position when pasting. when validating the resulting fragment, after the paste, the span is deemed invalid and removed, thus breaking the code by removing the marker.
This issue will be fixed in the next official tinymce minor release. There are some workarounds for this kind of issue. One is to add to add id and mce-data-type attribute to spans as valid elements (init setting). Example:
// The valid_elements option defines which elements will remain in the edited text when the editor saves.
valid_elements: "#[id|class|title|style]," +
"a[name|href|target|title]," +
"#p,-ol,-ul,-li,br,img[src],-sub,-sup,-b,-i,-u" +
"-span[data-mce-type]",