This is a migrated thread and some comments may be shown as answers.

How to trigger Observable functions

4 Answers 507 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Grant asked on 01 Aug 2017, 01:02 PM
    

4 Answers, 1 is accepted

Sort by
0
Grant
Top achievements
Rank 3
Iron
Iron
Iron
answered on 01 Aug 2017, 01:15 PM

Hi, 

First I have no idea how I posted an empty thread, I pressed enter to go to the net line, next thing the thread had been created.

Im very new to Observable objects and MVVM, and have having trouble with a specific scenario. My Example in Kendo Dojo should help this along, http://dojo.telerik.com/UVumA. I've created a over simplified login page where the 'login' button is only enabled once a user name, password and company are entered/selected.

So I have a form Reset button in my page, which we know clears any fields in its respective form when clicked. However when they are cleared, its not affecting the enabled status of the login button. As you see in the example, I have to manually clear each field (or probably one field) in the observable object for the 'LoginEnabled' to be triggered.

Can I simply trigger the loginEnabled to run when the reset is clicked? Is there a better way to achieve my goal?

Thanks and Kind Regards,
Grant

0
Accepted
Stefan
Telerik team
answered on 03 Aug 2017, 06:32 AM
Hello Grant,

Thank you for the provided example.

In this case, the fastest approach will be to set only one of the ViewModel fields to null.

The loginEnabled() function can be called inside the resetClicked() function using this.loginEnabled(), but this will not achieve the desired result as even after the reset the DropDown value will not return null and the button will not be disabled.

Also, please have in mind that if the MVVM approach is used we recommend initializing the widget using the MVVM approach as well:

http://demos.telerik.com/kendo-ui/dropdownlist/mvvm

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Grant
Top achievements
Rank 3
Iron
Iron
Iron
answered on 07 Aug 2017, 06:56 AM

Hi Stefan, 

Thanks for the reply. Your solution of setting one of the fields to null before triggering the loginEnabled() is great.

Is there a document (or do you have advise) that specifies when best to use MVVM vs. manual init. vs hybrid init? The reason is that Im using Spring Thymeleaf and sometimes titles/values/messages have to be read from a message.properties file for the sake of internationalization.

I look forward to you answer.

Thanks,
Grant

0
Stefan
Telerik team
answered on 09 Aug 2017, 05:46 AM
Hello Grant,

In general, we recommend using only one of the approaches MVVM or jQuery based on the needs and the specifics of the application. The recommendation is more based on the consistency of the application than on the limitations that may occur.

Still, a hybrid approach can be used if the specifics scenarios is requiring it as our widgets are using MVVM binding internally even if they are initialized using the jQuery approach.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Stefan
Telerik team
Share this question
or