I did not manage to run a simple javascript snippet in my view. Here is what I did:
1 - Installed coldbox-asset-bag module
2 - Included the following script in the file app_snippets.js
// Verify password changes
$(document).ready(function() {
function checkPass() {
//Store the password field objects into variables …
var pass1 = document.getElementById(‘pass1’);
var pass2 = document.getElementById(‘pass2’);
//Store the Confimation Message Object …
var message = document.getElementById(‘confirmMessage’);
//Set the colors we will be using …
var goodColor = “#66cc66”;
var badColor = “#ff6666”;
//Compare the values in the password field
//and the confirmation field
if(pass1.value == pass2.value){
//The passwords match.
//Set the color to the good color and inform
//the user that they have entered the correct password
pass2.style.backgroundColor = goodColor;
$(’#post’).removeAttr(‘disabled’);
message.style.color = goodColor;
message.innerHTML = “Passwords match!”
} else {
//The passwords do not match.
//Set the color to the bad color and
//notify the user.
pass2.style.backgroundColor = badColor;
$(’#post’).attr(“disabled”,“disabled”);
message.style.color = badColor;
message.innerHTML = “Passwords do not match!”
}
}
})
3 - Loaded that file in my event controller like that:
function changePassword(event,rc,prc){
// I display two fields side by side to verify a password input with a JS script
// called checkPass() before running the updatePassword event
// Load javascript and css dynamically in the views
prc.assetBag.addJavascriptToHead( “/includes/js/app_snippets.js” );
// Ensure that a sessionUserID is properly passed from the index view to RC via the form
event.paramValue(“sessionUserID”, rc.varID);
// Build a session user instance with the key passed in RC
prc.objUserBean = userSVC.read(rc.sessionUserID);
event.setView(“base/myaccount/changePassword”);
}
3 - Rendered the asset into the Views header like this:
#prc.assetBag.renderHead()#4 - Implemented Javascript call to the checkPass() function like this, within the above View:
#Ucase(request.tslFormTitle)#
5 - Dumped prc.assetBag to view its content. app_snippet.js not added to assetBag. Nothing happens, no javascript loaded after coldbox reinit, server re-start and whatever could have re-initialized my app.
Strange enough, the javascript that comes with Foundation tags works well … See attached screen (verifies that password input cannot be blank).
Any suggestions?