Hi,
I have a dialog with controls inside bound with Knockout. Everything works well for me except one thing: once user made some changes on dialog (like check some check boxes, type in some text) then close it, next time all the changes remain. To close the dialog, I just use this function: $("#print-dialog").igDialog("close");. Did you see this issue before and if yes, what was your solution to fix this?
FYI, my function to open the dialog follows:
function showPrintDialog(exam_id, exam_type) { if (print_first_time == true) { print_model = new printDialogViewModel(exam_id, exam_type); ko.applyBindings(print_model, document.getElementById('print-dialog')); $('#print-questions').customRadioCheck(); $('#print-answers').customRadioCheck(); $('#print-explanations').customRadioCheck(); $('#print-answer-key').customRadioCheck(); $('#print-blank-answer-sheet').customRadioCheck(); $('#print-range-text').igTextEditor(); $('#print-range-text').igTextEditor("option", "disabled", true); $('#print-exam-print-btn').igButton(); $('#print-exam-cancel-btn').igButton(); print_first_time = false; } else { // reinitialize the data print_model.Questions(true); print_model.Answers(true); print_model.Explanations(true); print_model.AnswerKey(false); print_model.BlankAnswerSheet(false); print_model.QuestionRangeText = ko.observable(""); $('#print-range-text').igTextEditor("option", "disabled", true); } $("#print-dialog").igDialog("open"); $(function () { });}
Thanks in advance.
Hi, Tangailam.
Thanks for using our product. I just have one question to clarify if I understood you right.
When the igDialog is closed, the container is just hidden, it's not destroyed. That's why when it's opened again, the container is just shown again, and nothing of the controls, bound with Knockout, is changed. Is your expectation that all the controls are with default values? Because igDialog closing/opening is not related and should not affect the Knockout functionality.
I will wait for your feedback and sorry if I didn't understand your question.
Best regards,
Nikolay
Hi Nikolay,
Thanks for your response. I would like to clarify more about my question. As you can see in the code snippet I posted above, I have reset the values of print_model to default. My expectation is the controls will get those default values and display them correctly. I debugged and found out that my print_model was reset properly, but the controls inside igDialog didn't show those value. This did not happen when I moved the controls outside igDialog. That's why I have to ask you for your support.
I hope this will help you understand my question better.
Thanks.
Using the sample from that verified post , I've just add a logic to reset the value when the dialog is closed and it is working fine. You can find attached a sample using igCombo, but it should be valid for any controls that have Knockout support. To run the sample you just need to have folder with Ignite UI source code. You can also see the discussion for more information about the igDialog and Knockout. Don't hesitate to ask if you have more questions.
Thank you Nikolay. Your code is very helpful.
I'm just checking if you need more help for this issue. Don't hesitate to ask, if you have more questions.
Nikolay Alipiev
Thanks for the sample. I guess it was not on purpose, but there was a exception due to the fact, that the rangeChanged handler was not defined in the ViewModel. Because of that of that reason, the print_first_time parameter was always true and the logic never reached the code where the data was initialized. I fixed that and the check boxes have their default values, when the igDialog is opened. It seems the problem is not related with the igDialog, but I will wait for your feedback for confirmation.
You can find attached the modified sample.
Thank you for your sample. It worked well but that doesn't solve my problem. I am attaching a code snippet which was extracted from my current project. When the dialog is shown for the first time, the check boxes and radios are checked properly. But once the dialog closed and reopened, they remains whatever user just select before. Would you please have a look at this and let me know your idea? Any comments are really appreciated.
Regards,