Custom Binding expression

Hi fuse,

I need custom expression like this;

<JavaScript>

module.exports={
     formatDate:function(val,format){
       //some operation

      return val;
     }
};

</JavaScript>
<Text Value="{= formatDate({processDate},'dd MM YYYY') }" />

Is something like this possible?

Hi Hilmi,

there is no ready UX expression for formatting date, but it looks like you have already figured out that you could use JavaScript to achieve what you wanted. Let’s take it a step further and make it work!

<JavaScript>
	var Observable = require("FuseJS/Observable");
	var date = Observable("some_date_string_here");

	function formatDate(val, format) {
		// some operation
	}

	var formatted = date.map(function(x) {
		return formatDate(x, 'dd MM YYYY');
	});

	// TODO:
	// 1: change the date.value when you need to process a new value.
	// 2: done. the variable "formatted" updates reactively every time "date" observable changes.
	date.value = "some_other_date_string";

	module.exports = {
		formatted: formatted
	};
</JavaScript>
<Text Value="{formatted}" />

Hope this helps!

Hi Uldis,

Thanks for reply, but i have many rows in data formatted foreach loop take a long time.

data.forEach(function(item){
item.processDate=formatDate(item.processDate);
});

Any idea?

Hi Hilmi,

you should probably do the date formatting when you first read the data, before you stuff it in the observable. That way, the formatted date will already be there and no run-time mapping will be required.