Instead of doing this with calculation, I would use a custom parsley validator. Although calculations could be set up to prevent the issue like Matthew mentioned, I think a validator has a lot more flexibility.
For example, if you use a validator, you could make it so the form wouldn't submit even if the button was visible because it would fail validation unless the password fields matched.
In the code below, I have a "passwordInput" class set on the main input, and a "passwordConfirm" class set on the read-only field. I also included code to hide/disable the button in comments.
$(document).ready(function(){
//$('#myButton').hide().prop('disabled',true);
// assign validator to password field
$('.passwordInput input').attr({
'placeholder':'Enter your password',
'type':'password',
'data-parsley-passwordconfirmation':''
});
});
// custom validator for password confirmation
window.Parsley.addValidator('passwordconfirmation', {
validateString: function(value, requirement, field) {
var password = $('.passwordInput input').val();
var confirm = $('.passwordConfirm input').val();
var correct = (password == confirm && confirm != '');
//$('#myButton').toggle(correct).prop('disabled',!correct);
return correct;
},
messages: {
en: 'Incorrect password.',
}
});
Now that being said, doing a password this way is not especially secure, especially since someone could inspect the page and find the comparison field.
However, if security isn't a concern and you're using a lookup to pull the password based on the username, then I think a better way would be with a stored procedure.
Instead of populating the form with a value someone could find, build a stored procedure in your database that accepts username and password as the parameters.
Then, have that procedure return a true/false or 0/1 value to say whether or not a match was found and pull that value into your form instead.
That way, you can have field rules to show/hide the button based on whether or not the stored procedure returns a good value and you don't have the password somewhere they can check.