{"id":1387,"date":"2022-08-30T15:16:06","date_gmt":"2022-08-30T15:16:06","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/15\/failure-invoking-a-modal-window-thru-jquery-in-yii-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:06","modified_gmt":"2022-08-30T15:16:06","slug":"failure-invoking-a-modal-window-thru-jquery-in-yii-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/failure-invoking-a-modal-window-thru-jquery-in-yii-collection-of-common-programming-errors\/","title":{"rendered":"Failure invoking a modal window thru jquery in Yii-Collection of common programming errors"},"content":{"rendered":"<p>I try to add modal window to my yii app. For this i use jquery from the framework. Yet, i does not work with jquery (1.8.3) from the framework: <strong>framework\/web\/js\/source<\/strong> The error is <em>Uncaught TypeError: Object [object Object] has no method &#8216;modal&#8217;<\/em> to this line:<\/p>\n<pre><code>$('#dataModal').modal().css({\n            width: 'auto',\n            height: 'auto',\n    });\n<\/code><\/pre>\n<p>(see the full code below). The same happens when i exchange modal() to dialog().<\/p>\n<p>Yet, when i try to upload the latest jquery (1.10.2) thru googleapis by registering as a client script it works (only one time at each view call though): <strong>config\/main.php:<\/strong><\/p>\n<pre><code>'components'=&gt;array(\n...\n 'clientScript'=&gt;array(\n    'packages'=&gt;array(\n        'jquery'=&gt;array(\n            'baseUrl'=&gt;'\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1\/',\n            'js'=&gt;array('jquery.min.js'),\n        ),\n    ),\n ),\n<\/code><\/pre>\n<p>and register in a view:<\/p>\n<pre><code>Yii::app()-&gt;clientScript-&gt;registerCoreScript('jquery');\n<\/code><\/pre>\n<p>The full code pertaining to the case is here:<\/p>\n<pre><code>      \n\n    \n        \u00d7\n        <\/code><\/pre>\n<pre>\n        \n    \n    \n    \n    \n    \n\n \n ...\n\n\/\/ this function calls the modal thru AJAX\n$('#data-select-btn').click(function(){\n   var buttn = this; \n   \/\/ $(buttn).button('loading'); \n    $.ajax({\n      url: \"\", \/*LoadDataCheckBox*\/\n      cache: false,\n      data: \"type=\"+$(\"#Order_type\").val(),\n      success: function(html){\n        $(\".modal-body\").html(html);       \n        \/\/$(buttn).button('reset');\n        $('#dataModal').modal().css({\n            width: 'auto',\n            height: 'auto',\n            'margin-top': '-50px',\n            'margin-left': function () {\n                return -($(this).width() \/ 2) - 80;\n            },\n        });\n      }          \n    });\n})\n\n<\/pre>\n<p><code>Jquery-ui is also included:<\/code><\/p>\n<pre><code><code>\n\n<\/code><\/code><\/pre>\n<h2>Update<\/h2>\n<p>As far as Yii bootstrap extention i do use it, and in bootstrap.js there is the modal class definition and plugin definition. this file is being loaded after jquery, yet before jquery-iu, <strong>does sequence matter?<\/strong><\/p>\n<pre><code>\n...\n\n<\/code><\/pre>\n<p>end of view file:<\/p>\n<pre><code>\n\n<\/code><\/pre>\n<ol>\n<li>\n<p><strong>The sequence matters.<\/strong><\/p>\n<p>You should first load jquery, then jquery-ui, thw bootsttrap.js<\/p>\n<p>Try indicate the position in the registerScript:<\/p>\n<pre><code>Yii::app()-&gt;clientScript-&gt;registerCoreScript('jquery', CClientScript::POS_HEAD);\n<\/code><\/pre>\n<p>More info here: http:\/\/www.yiiframework.com\/doc\/api\/1.1\/CClientScript#registerScriptFile-detail<\/p>\n<p>And how you are including the jQuery UI?<\/p>\n<p>===EDIT=== Try changing the order of the scripts in the config\/main using this:<\/p>\n<pre><code>'components'=&gt;array(\n...\n    'clientScript' =&gt; array(\n        'coreScriptPosition' =&gt; CClientScript::POS_END,\n    )\n),\n<\/code><\/pre>\n<p>If nothing work, just disable the autoloding like that:<\/p>\n<pre><code>'clientScript' =&gt; array(\n    'scriptMap'=&gt;array(\n        'jquery.js'=&gt;false,\n        'jquery.min.js'=&gt;false\n    ),\n),\n<\/code><\/pre>\n<p>And load then just like the old days \ud83d\ude09<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-15 09:08:09. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I try to add modal window to my yii app. For this i use jquery from the framework. Yet, i does not work with jquery (1.8.3) from the framework: framework\/web\/js\/source The error is Uncaught TypeError: Object [object Object] has no method &#8216;modal&#8217; to this line: $(&#8216;#dataModal&#8217;).modal().css({ width: &#8216;auto&#8217;, height: &#8216;auto&#8217;, }); (see the full code [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1387","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1387"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1387\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}