Coverting JS from jQuery UI to Bootstrap










0















I need some help converting existing JS functionality that was originally written with jQuery UI and now is moving to Bootstrap + jQuery. This particular code is using a form for uploading an image file and on submit it brings up a modal window with two options: "I Agree" and "Cancel". Cancel simply closes modal window but I agree submits the form.



Here's the old code:



HTML (old)



<input type="file" name="customLogo"> 
<input class="btn" type="submit" name="customLogoUpload" value="Upload File">

<div id="logoUploadLegal" class="jq-dialog txtAlnLt" title="Legal">
By uploading a file ...</p>
</div>


JS (old)



if( $(form_selector + " .customLogo").length ) 
test_edit_form_legal_notice_dialog_hook(form_selector, "#logoUploadLegal", "input[name=customLogoUpload]");


function test_edit_form_legal_notice_dialog_hook(form_selector, dialog_selector, upload_btn_selector)

var upload_button_used = false,
legal_ok = false;

$(form_selector + " input:submit").on("click", function()
if( $(form_selector + " " + upload_btn_selector).is(this) )
upload_button_used = true;
else
upload_button_used = false;
);

$(form_selector).on("submit", function()
if( !$(form_selector + " input:file").val().length )
return true;

if( legal_ok )
return true;

$(dialog_selector).dialog(
modal: true,
draggable: true,
resizable: true,
width: 400,

buttons:
"I agree" : function()
legal_ok = true;
if( upload_button_used )
$(form_selector + " " + upload_btn_selector).click();
else
$(form_selector).submit();
,
"Cancel" : function ()
$(this).dialog("close");


);

return false;
);



JS (new)



and here's my attempt to convert to the new code. I just don't quite understand how to engage modal button...



HTML (new)



<div class="form-group">
<input id="customLogo" type="file" name="customLogo">
</div>
<input class="btn btn-default" type="submit" name="customLogoUpload" value="Upload File">

<div id="logoUploadLegal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header h4">
Legal
</div>
<div class="modal-body">
By uploading a file ...</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default logoUploadLegalConfirm" data-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>


JS (old)



function test_edit_form_legal_notice_dialog_hook(form_selector, dialog_selector, upload_btn_selector)

var upload_button_used = false,
legal_ok = false;

$(form_selector + " input:submit").on("click", function()
if( $(form_selector + " " + upload_btn_selector).is(this) )
upload_button_used = true;
else
upload_button_used = false;
);

$(form_selector).on("submit", function()
if( !$(form_selector + " input:file").val().length )
return true;

if( legal_ok )
return true;


$(dialog_selector).modal(function()

$(dialog_selector).on('click', 'button', function()
console.log(upload_button_used);
);
//
// buttons:
// "I agree" : function()
// legal_ok = true;
// if( upload_button_used )
// $(form_selector + " " + upload_btn_selector).click();
// else
// $(form_selector).submit();
// ,
// "Cancel" : function ()
// $(this).dialog("close");
//
//
);

return false;
);










share|improve this question






















  • You mean, how to actually display the modal when the user clicks "upload file"? Simply edit the upload button to include two attributes: data-toggle="modal" data-target="logoUploadLegal" -- bootstrap will handle the display bit for you. See it working here: jsfiddle.net/snowMonkey/vtcpg62x/3

    – Snowmonkey
    Nov 14 '18 at 23:08















0















I need some help converting existing JS functionality that was originally written with jQuery UI and now is moving to Bootstrap + jQuery. This particular code is using a form for uploading an image file and on submit it brings up a modal window with two options: "I Agree" and "Cancel". Cancel simply closes modal window but I agree submits the form.



Here's the old code:



HTML (old)



<input type="file" name="customLogo"> 
<input class="btn" type="submit" name="customLogoUpload" value="Upload File">

<div id="logoUploadLegal" class="jq-dialog txtAlnLt" title="Legal">
By uploading a file ...</p>
</div>


JS (old)



if( $(form_selector + " .customLogo").length ) 
test_edit_form_legal_notice_dialog_hook(form_selector, "#logoUploadLegal", "input[name=customLogoUpload]");


function test_edit_form_legal_notice_dialog_hook(form_selector, dialog_selector, upload_btn_selector)

var upload_button_used = false,
legal_ok = false;

$(form_selector + " input:submit").on("click", function()
if( $(form_selector + " " + upload_btn_selector).is(this) )
upload_button_used = true;
else
upload_button_used = false;
);

$(form_selector).on("submit", function()
if( !$(form_selector + " input:file").val().length )
return true;

if( legal_ok )
return true;

$(dialog_selector).dialog(
modal: true,
draggable: true,
resizable: true,
width: 400,

buttons:
"I agree" : function()
legal_ok = true;
if( upload_button_used )
$(form_selector + " " + upload_btn_selector).click();
else
$(form_selector).submit();
,
"Cancel" : function ()
$(this).dialog("close");


);

return false;
);



JS (new)



and here's my attempt to convert to the new code. I just don't quite understand how to engage modal button...



HTML (new)



<div class="form-group">
<input id="customLogo" type="file" name="customLogo">
</div>
<input class="btn btn-default" type="submit" name="customLogoUpload" value="Upload File">

<div id="logoUploadLegal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header h4">
Legal
</div>
<div class="modal-body">
By uploading a file ...</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default logoUploadLegalConfirm" data-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>


JS (old)



function test_edit_form_legal_notice_dialog_hook(form_selector, dialog_selector, upload_btn_selector)

var upload_button_used = false,
legal_ok = false;

$(form_selector + " input:submit").on("click", function()
if( $(form_selector + " " + upload_btn_selector).is(this) )
upload_button_used = true;
else
upload_button_used = false;
);

$(form_selector).on("submit", function()
if( !$(form_selector + " input:file").val().length )
return true;

if( legal_ok )
return true;


$(dialog_selector).modal(function()

$(dialog_selector).on('click', 'button', function()
console.log(upload_button_used);
);
//
// buttons:
// "I agree" : function()
// legal_ok = true;
// if( upload_button_used )
// $(form_selector + " " + upload_btn_selector).click();
// else
// $(form_selector).submit();
// ,
// "Cancel" : function ()
// $(this).dialog("close");
//
//
);

return false;
);










share|improve this question






















  • You mean, how to actually display the modal when the user clicks "upload file"? Simply edit the upload button to include two attributes: data-toggle="modal" data-target="logoUploadLegal" -- bootstrap will handle the display bit for you. See it working here: jsfiddle.net/snowMonkey/vtcpg62x/3

    – Snowmonkey
    Nov 14 '18 at 23:08













0












0








0








I need some help converting existing JS functionality that was originally written with jQuery UI and now is moving to Bootstrap + jQuery. This particular code is using a form for uploading an image file and on submit it brings up a modal window with two options: "I Agree" and "Cancel". Cancel simply closes modal window but I agree submits the form.



Here's the old code:



HTML (old)



<input type="file" name="customLogo"> 
<input class="btn" type="submit" name="customLogoUpload" value="Upload File">

<div id="logoUploadLegal" class="jq-dialog txtAlnLt" title="Legal">
By uploading a file ...</p>
</div>


JS (old)



if( $(form_selector + " .customLogo").length ) 
test_edit_form_legal_notice_dialog_hook(form_selector, "#logoUploadLegal", "input[name=customLogoUpload]");


function test_edit_form_legal_notice_dialog_hook(form_selector, dialog_selector, upload_btn_selector)

var upload_button_used = false,
legal_ok = false;

$(form_selector + " input:submit").on("click", function()
if( $(form_selector + " " + upload_btn_selector).is(this) )
upload_button_used = true;
else
upload_button_used = false;
);

$(form_selector).on("submit", function()
if( !$(form_selector + " input:file").val().length )
return true;

if( legal_ok )
return true;

$(dialog_selector).dialog(
modal: true,
draggable: true,
resizable: true,
width: 400,

buttons:
"I agree" : function()
legal_ok = true;
if( upload_button_used )
$(form_selector + " " + upload_btn_selector).click();
else
$(form_selector).submit();
,
"Cancel" : function ()
$(this).dialog("close");


);

return false;
);



JS (new)



and here's my attempt to convert to the new code. I just don't quite understand how to engage modal button...



HTML (new)



<div class="form-group">
<input id="customLogo" type="file" name="customLogo">
</div>
<input class="btn btn-default" type="submit" name="customLogoUpload" value="Upload File">

<div id="logoUploadLegal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header h4">
Legal
</div>
<div class="modal-body">
By uploading a file ...</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default logoUploadLegalConfirm" data-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>


JS (old)



function test_edit_form_legal_notice_dialog_hook(form_selector, dialog_selector, upload_btn_selector)

var upload_button_used = false,
legal_ok = false;

$(form_selector + " input:submit").on("click", function()
if( $(form_selector + " " + upload_btn_selector).is(this) )
upload_button_used = true;
else
upload_button_used = false;
);

$(form_selector).on("submit", function()
if( !$(form_selector + " input:file").val().length )
return true;

if( legal_ok )
return true;


$(dialog_selector).modal(function()

$(dialog_selector).on('click', 'button', function()
console.log(upload_button_used);
);
//
// buttons:
// "I agree" : function()
// legal_ok = true;
// if( upload_button_used )
// $(form_selector + " " + upload_btn_selector).click();
// else
// $(form_selector).submit();
// ,
// "Cancel" : function ()
// $(this).dialog("close");
//
//
);

return false;
);










share|improve this question














I need some help converting existing JS functionality that was originally written with jQuery UI and now is moving to Bootstrap + jQuery. This particular code is using a form for uploading an image file and on submit it brings up a modal window with two options: "I Agree" and "Cancel". Cancel simply closes modal window but I agree submits the form.



Here's the old code:



HTML (old)



<input type="file" name="customLogo"> 
<input class="btn" type="submit" name="customLogoUpload" value="Upload File">

<div id="logoUploadLegal" class="jq-dialog txtAlnLt" title="Legal">
By uploading a file ...</p>
</div>


JS (old)



if( $(form_selector + " .customLogo").length ) 
test_edit_form_legal_notice_dialog_hook(form_selector, "#logoUploadLegal", "input[name=customLogoUpload]");


function test_edit_form_legal_notice_dialog_hook(form_selector, dialog_selector, upload_btn_selector)

var upload_button_used = false,
legal_ok = false;

$(form_selector + " input:submit").on("click", function()
if( $(form_selector + " " + upload_btn_selector).is(this) )
upload_button_used = true;
else
upload_button_used = false;
);

$(form_selector).on("submit", function()
if( !$(form_selector + " input:file").val().length )
return true;

if( legal_ok )
return true;

$(dialog_selector).dialog(
modal: true,
draggable: true,
resizable: true,
width: 400,

buttons:
"I agree" : function()
legal_ok = true;
if( upload_button_used )
$(form_selector + " " + upload_btn_selector).click();
else
$(form_selector).submit();
,
"Cancel" : function ()
$(this).dialog("close");


);

return false;
);



JS (new)



and here's my attempt to convert to the new code. I just don't quite understand how to engage modal button...



HTML (new)



<div class="form-group">
<input id="customLogo" type="file" name="customLogo">
</div>
<input class="btn btn-default" type="submit" name="customLogoUpload" value="Upload File">

<div id="logoUploadLegal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header h4">
Legal
</div>
<div class="modal-body">
By uploading a file ...</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default logoUploadLegalConfirm" data-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>


JS (old)



function test_edit_form_legal_notice_dialog_hook(form_selector, dialog_selector, upload_btn_selector)

var upload_button_used = false,
legal_ok = false;

$(form_selector + " input:submit").on("click", function()
if( $(form_selector + " " + upload_btn_selector).is(this) )
upload_button_used = true;
else
upload_button_used = false;
);

$(form_selector).on("submit", function()
if( !$(form_selector + " input:file").val().length )
return true;

if( legal_ok )
return true;


$(dialog_selector).modal(function()

$(dialog_selector).on('click', 'button', function()
console.log(upload_button_used);
);
//
// buttons:
// "I agree" : function()
// legal_ok = true;
// if( upload_button_used )
// $(form_selector + " " + upload_btn_selector).click();
// else
// $(form_selector).submit();
// ,
// "Cancel" : function ()
// $(this).dialog("close");
//
//
);

return false;
);







jquery






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 21:24









santasanta

5,93839128210




5,93839128210












  • You mean, how to actually display the modal when the user clicks "upload file"? Simply edit the upload button to include two attributes: data-toggle="modal" data-target="logoUploadLegal" -- bootstrap will handle the display bit for you. See it working here: jsfiddle.net/snowMonkey/vtcpg62x/3

    – Snowmonkey
    Nov 14 '18 at 23:08

















  • You mean, how to actually display the modal when the user clicks "upload file"? Simply edit the upload button to include two attributes: data-toggle="modal" data-target="logoUploadLegal" -- bootstrap will handle the display bit for you. See it working here: jsfiddle.net/snowMonkey/vtcpg62x/3

    – Snowmonkey
    Nov 14 '18 at 23:08
















You mean, how to actually display the modal when the user clicks "upload file"? Simply edit the upload button to include two attributes: data-toggle="modal" data-target="logoUploadLegal" -- bootstrap will handle the display bit for you. See it working here: jsfiddle.net/snowMonkey/vtcpg62x/3

– Snowmonkey
Nov 14 '18 at 23:08





You mean, how to actually display the modal when the user clicks "upload file"? Simply edit the upload button to include two attributes: data-toggle="modal" data-target="logoUploadLegal" -- bootstrap will handle the display bit for you. See it working here: jsfiddle.net/snowMonkey/vtcpg62x/3

– Snowmonkey
Nov 14 '18 at 23:08












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308937%2fcoverting-js-from-jquery-ui-to-bootstrap%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308937%2fcoverting-js-from-jquery-ui-to-bootstrap%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto