Question

I have bind some variables to the input fields on $(document).ready

var appdetail = kendo.observable({
    addAppName: "TESTAPP",
    addAppId: "13579"

});

kendo.bind($("#formAdd"), appdetail);

the form is inside a modalview. When I open the modal view I can see "TESTAPP" and "13579" as the default values. The problem is, when I click the button, I am calling a function AddRecord using data-click.. and in this function I am not able to get the values of the forms in a way like

var application_name = appdetail.get("addAppName");

is there a way to make the values available in other functions?


I am adding the HTML & JS code.. When click the ADD button, default values (TESTDB & 13579) are not comming to my modalview window. All fields are blank. When I click the Authorize button on the dialog, TESTDB which is the default value is returning as the alert message whatever the dialog input field is.

the current code is

Javascript :

var app = new kendo.mobile.Application(document.body, {layout: "mobile-tabstrip", loading: "<h1>Please wait...</h1>"});

var appdetail = kendo.observable({
    addAppName: "TESTAPP",
    addAppId: "13579"
});


kendo.bind($("#formAdd"), appdetail);


//alert(appdetail.get("addAppName"));



function closeModalViewAdd() {
    $("#modalview-app-add").kendoMobileModalView("close");
};


function showWindow() {
  $("#modalview-app-add").data("kendoMobileModalView").open();


}

function addToJson() {
  alert(appdetail.get("addAppName"));
 // console.log(appdetail.addAppId);
}

HTML :

<!doctype html>
<html>
    <head>
        <title>Kendo UI Mobile</title>
            <meta charset="utf-8" />
            <link href="../styles/kendo.mobile.all.min.css" rel="stylesheet" />
            <script src="../js/jquery.min.js"></script>
            <script src="../js/kendo.mobile.min.js"></script>

        <!-- Encigo Specific Page Scripts--->           
            <script src="../js/mytest.js"></script>

            </head>
    <body>


<!-- LAYOUT: default --------------------------------- start --------------->
        <div data-role="layout" data-id="default">
                    <header data-role="header">
                        <div data-role="navbar">
                            <span data-role="view-title"></span>
                        </div>
                    </header>

                    <footer data-role="footer" data-position="fixed">
                        <div data-role="tabstrip">
                            <a data-icon="globe" href="#languages">Languages</a>
                            <a data-icon="settings" href="#applications">Applications</a>
                            <a data-icon="contacts" href="#login">Login</a>


                        </div>
                    </footer>
        </div>

<!-- LAYOUT: default --------------------------------- finish --------------->

<!-- VIEW: modelview add --------------------------------- start --------------->

        <div data-role="modalview" id="modalview-app-add" style="width: 95%;" data-show="bindNewDataVar">

            <form id="formAdd">
                <ul data-role="listview" data-style="inset">
                    <li>
                        <label>App Name
                            <input type="text" value="" id="app_name" data-bind="value: addAppName"/>
                        </label>
                    </li>

                    <li>
                        <label>App Id
                            <input type="number" value="" id="extapp_id" data-bind="value: addAppId"/>
                        </label>
                    </li>

                </ul>

                    <p align="center"><a data-role="button" style="width: 35%" data-icon="play" align="center" id="buttonauthorize" data-click="addToJson" >Authorize</a><a data-role="button" style="width: 35%" data-icon="rewind" align="center"  data-click="closeModalViewAdd" id="canceldialogbutton" >Cancel</a>

                    <!-- <br><a data-role="button"  data-icon="pause" style="width: 35%" align="left" id="resetauthorization">Reset</a> -->
                    </p>


            </form>

        </div>
<!-- VIEW: modelview add --------------------------------- finish --------------->


<!-- VIEW: applications --------------------------------- start --------------->

        <div id="applications" data-role="view"  data-title="Defined Applications" data-layout="default">

            <p align="center"><a  style="width: 90%" data-role="button" data-rel="modalview" onclick="showWindow()" id="AddApplication" data-icon="add">Add</a></p>

        </div>


        </div>
<!-- VIEW: applications --------------------------------- finish --------------->


    </body>
</html>
Was it helpful?

Solution

I recommend making use the data-model property of the view and modal-view.

<div data-role="modalview" id="modalview-app-add" 
style="width: 95%;" data-show="bindNewDataVar" data-model="appdetail">

and

<div id="applications" data-role="view"
data-title="Defined Applications" data-layout="default" data-model="appdetail">

See working sample at... http://jsbin.com/fezel/1/edit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top