Closed icfantv closed 9 years ago
The expressionProperties
are formlyExpressions
. See the docs here: http://docs.angular-formly.com/v5.2.1/docs/formly-expressions
Let me know if you need more assistance :-)
Thanks! Will give this a go.
Worked perfectly (I still don't know why I sometimes am surprised when that happens). Thanks again.
Hi icfantv,
I am new in formly and I tring to implement multilingual UI so I need to run a function in the 'templateOptions.labelProp' so I have the following
{
key: 'country',
type: 'select',
templateOptions: {
label: 'Country of operation',
options: [],
valueProp:'id',
labelProp:'code',
required: false
},
expressionProperties: {
'templateOptions.labelProp': function($viewValue, $modelValue, scope) {
return "_TESTFUNCTION";
}
},
controller: function($scope,$log, CountryService) {
CountryService.get().then(function (results)
{
if(results)
{
$scope.options.templateOptions.options = results.data;
return results.data;
}
});
}
}
I trying to use a function in the expressionProperties and it is not working. Can you help me in giving me a example how you did, please?
@hmendezm, the best way to get help is to create an example using http://help.angular-formly.com. Just looking at your code, it appears that it should work fine. So an example is more helpful.
This is the example. If you see the values are undefine http://jsbin.com/vocexa/edit?js,output
I do not know what I am doing wrong
best regards
Wait, so are you trying to do this?
Hi Kent, No, I do not want to change the title of the dropdown. I am try to change the label of the items in the dropdown list when user change the language. So my guess was to use a function that allow me to replace the value of the language. let me give you a example:
English Spanish Dominic Republic República Dominicana
In the dropdown will have english text (eg. Dominic Republic) initially but if user decides to change to Spanish text the label should be changed (eg. Republica dominicana)
In a select what usually I have in the html is the following
<select class="form-control" ng-model="assesstment.Country" ng-options="country.id as country.translations[getLanguageID(country.translations,selectedLanguageCode,'language_id')].name for country in countries" ng-change="changedcountry(assesstment.Country)" >
</select>
The function getLanguageID will just to return value between 0 to 5 which is the index in the array (country.translations) that is location of the selected language.
JSON
[{"id":1,"region_id":1,"code":"Afghanistan","translations":[{"country_id":1,"language_id":1,"name":"Afghanistan"},{"country_id":1,"language_id":2,"name":"Afghanistan"},{"country_id":1,"language_id":3,"name":"Afganistán"},{"country_id":1,"language_id":4,"name":"Afghanistan"},{"country_id":1,"language_id":5,"name":"Afeganistão"},{"country_id":1,"language_id":6,"name":"Afghanistan"}]},
{"id":136,"region_id":5,"code":"Albania","translations":[{"country_id":136,"language_id":1,"name":"Albania"},{"country_id":136,"language_id":2,"name":"Albanie"},{"country_id":136,"language_id":3,"name":"Albania"},{"country_id":136,"language_id":4,"name":"Albanien"},{"country_id":136,"language_id":5,"name":"Albânia"},{"country_id":136,"language_id":6,"name":"Albania"}]},
{"id":48,"region_id":2,"code":"Algeria","translations":[{"country_id":48,"language_id":1,"name":"Algeria"},{"country_id":48,"language_id":2,"name":"Algérie"},{"country_id":48,"language_id":3,"name":"Argelia"},{"country_id":48,"language_id":4,"name":"Alrgerien"},{"country_id":48,"language_id":5,"name":"Argélia"},{"country_id":48,"language_id":6,"name":"Algeria"}]},
{"id":137,"region_id":5,"code":"Andorra","translations":[{"country_id":137,"language_id":1,"name":"Andorra"},{"country_id":137,"language_id":2,"name":"Andorre"},{"country_id":137,"language_id":3,"name":"Andorra"},{"country_id":137,"language_id":4,"name":"Andorra"},{"country_id":137,"language_id":5,"name":"Andorra"},{"country_id":137,"language_id":6,"name":"Andorra"}]}]
I hope this explains my problem/situation.
Thank you very much for reply and take time in this Best regards Henry
Ah, maybe this will point you in the right direction: http://jsbin.com/yubato/edit?js,output
Thanks Kent, I will check the link and see how I can put translate to work :-) if I am successful I will create an example using formly, so the other developers who need translate can use.
Thanks again Have a nice day! H
How do you specify which option to disable?
I'm using the bootstrap templates (so I apologize in advance if this is a template issue) and it appears that if I specify a function as follows:
The function is not actually executed. Like, ever.
Is this by design? Is this a limitation in formly? Am I doing something wrong? Thanks.