I’m working on a user creation fixlet, and I’d like to include a “verify password” field to ensure the password was entered correctly.
Looking at the example in the Creating Parameterized Fixlets guide, I see the following code for validating parameters:
<MIMEField>
<Name>ParameterValidatorTag</Name>
<Value><![CDATA[{
validateUserName : function (validationObj ) {
var currentValue = validationObj["currentValue"];
if ( !currentValue.match(/^[a-z]{1,30}$/i))
return "The name format is not correct";
}
}]]></Value>
</MIMEField>
I see what we’re passing validationObj, but how do I call another variable to compare validationObj against?
I am not sure where you grabbed the example from cause it differs to what I have used/familiar with (certainly never used MIMEField values). The common example is something along those lines: https://bigfix.me/fixlet/details/3678 and the code for it looks roughly:
<INPUT id=secret type=password name=secret> <script>
document.body.ontakeaction = function() {
var theSecret = document.getElementById( "secret" ).value;
TakeSecureFixletAction( Relevance('id of current fixlet'), Relevance('id of current bes site'), "Action1", {}, { secret: theSecret, secret2: 'myHardcodedSecret-42' } );
return false;
}
</script>
and yes, you can add as many input types (check buttons, options, textarea, etc), as long as you write the javascript to read their name/value and pass it the execution it works. You do have an option to pass them as “secure” and “insecure”, and any combination thereof.
As far as error-checking, you can build that directly in the takeaction function with a few if statements and “return” if they are matched - example one I did and I chose to pass them all as insecure parameters (values visible in console and logs):
<script>
function _takeAction(){
var ptype = document.getElementById('ptype').value.toString();
var pproperty = document.getElementById('pproperty').value.toString();
var pdrive = document.getElementById('pdrive').value.toString();
var ptag = document.getElementById('ptag').value.toString();
if (pproperty == "") {
alert("Specify property!");
return;
}
if (ptype == "") {
alert("Specify action type!");
return;
}
if (pdrive == "") {
alert("Specify drive letter type!");
return;
}
TakeSecureFixletAction( Relevance('id of current fixlet'), Relevance('id of current bes site'), "Action1", {ptype: ptype, pproperty: pproperty, pdrive: pdrive, ptag: ptag}, {});
}
document.body.ontakeaction = function() { _takeAction(); return false; }
</script>
Using the method you shared, how do I specify “secure” or “insecure”? Is that implied when type=password? Or is it applied to all variables when called by TakeSecureFixletAction?
It’s where you pass the name/value keys. The function TakeSecureFixletAction takes 5 parameters by default in order:
ID of fixlet (obviously best to leave the dynamic relevance but hypothetically you can hardcode an integer value)
ID of site of fixlet (obviously best to leave the dynamic relevance but hypothetically you can hardcode an integer value)
If your action has more than one action then you may want to write something dynamic but if it is a single action then the default “Action1” should do fine
List of unsecure parameters (in the form of comma separated name/value pairs)
List of secure parameters
(in the form of comma separated name/value pairs)
Based on the above - example where all parameters are passed as insecure:
TakeSecureFixletAction( Relevance('id of current fixlet'), Relevance('id of current bes site'), "Action1", {ptype: ptype, pproperty: pproperty, pdrive: pdrive, ptag: ptag}, {});
Based on the above - example where all parameters are passed as secure:
TakeSecureFixletAction( Relevance('id of current fixlet'), Relevance('id of current bes site'), "Action1", {}, {ptype: ptype, pproperty: pproperty, pdrive: pdrive, ptag: ptag});
Based on the above - example where some parameters are passed as insecure and some as secure:
TakeSecureFixletAction( Relevance('id of current fixlet'), Relevance('id of current bes site'), "Action1", {ptype: ptype, pproperty: pproperty}, {pdrive: pdrive, ptag: ptag});
Thank you! I’ve been experimenting with this new (to me) way of creating parameterized fixlets. A few questions:
I think I’m doing something wrong with my check script.
<script>
document.body.ontakeaction = function() {
var username = document.getElementById( "username" ).value;
var password1 = document.getElementById( "password1" ).value;
var password2 = document.getElementById( "password2" ).value;
if (username == ""){
alert("Username cannot be blank");
return;
}
if (password1 == ""){
alert("Password cannot be blank");
return;
}
if (password2 == ""){
alert("Confirm password");
return;
}
TakeSecureFixletAction( Relevance('id of current fixlet'), Relevance('id of current bes site'), "Action1", {username: username}, {password1: password1, password2: password2} );
return false;
}
</script>
I receive a popup when the field is blank, but the fixlet is not stopped from deploying. After hitting “Okay” on the popup, I can continue deploying the fixlet like normal. (I haven’t added anything yet to check if Password1 == Password2 )
Is there any way to “beautify” the input forms to look like the MIMEType fields? I tried placing them in a table, but the table doesn’t render/look nice.
Try adding .toString() at the end when defining the variables - it won’t matter when passing it to the function but it may make a difference in the if statements.
I haven’t played around with that at all (“always the programmer, never the designer” mentality) but if I had to do would probably do it via css: CSS Forms
An approach I’ve used for getting the layout for fixlet description etc has been to use an HTML editor to design and create the html code then copy the code to the BES file.