I'm posting this because it could really be a time saver for someone.
Where I live we use a checksum at the end of our ID number, this checksum is obtained with an algorithm called Modulus 11. With this code you can add RUT validation to the text fields, but you could also break CF6 so back up the files involved before doing anything and proceed at your own risk!
Edit this file:
libraries/cegcore2/assets/js/g2.forms.js
And add the following function right after the email rules function (line 17 in my file):
Also modify this file to add the button under the validation tab in the text field options:
libraries/cegcore2/admin/extensions/chronofc/views/field_text/field_text_config.php
change line 103 where it says "two fields" to "three fields" so it looks like this:
Then in line 118 right after the div block for URL validation add this:
I strongly suggest adding a specific mask for the RUT to avoid problems with the dots and hyphen since THIS validation will ask for them (E.g. 20.234.234-K). This can be easily done by adding this at line 220:
That's it! Hope it helps someone someday.
Where I live we use a checksum at the end of our ID number, this checksum is obtained with an algorithm called Modulus 11. With this code you can add RUT validation to the text fields, but you could also break CF6 so back up the files involved before doing anything and proceed at your own risk!
Edit this file:
libraries/cegcore2/assets/js/g2.forms.js
And add the following function right after the email rules function (line 17 in my file):
jQuery.fn.form.settings.rules.rut = function(value){
if(value.match(/^\d{1,2}\.\d{3}\.\d{3}\-(\d|k|K)$/)){
var dv = value.slice(-1);
var rut=value.replace(/\.|\-/g,"");
var j = 2;
var sum = 0;
var i = (rut.length-1);
while (i--) {
if(j>7) j=2;
sum += rut.charAt(i) * j;
j++;
}
var dv2;
dv2=(11-(sum%11));
if (dv2==10) dv2="K";
if (dv2==11) dv2=0;
if(dv2==dv){
return true;
}else{
return false;
}
}else{
return false;
}
};
Also modify this file to add the button under the validation tab in the text field options:
libraries/cegcore2/admin/extensions/chronofc/views/field_text/field_text_config.php
change line 103 where it says "two fields" to "three fields" so it looks like this:
<div class="three fields">
Then in line 118 right after the div block for URL validation add this:
<div class="field">
<div class="ui checkbox toggle red">
<input type="hidden" name="Connection[views][<?php echo $n; ?>][validation][rut]" data-ghost="1" value="">
<input type="checkbox" class="hidden" name="Connection[views][<?php echo $n; ?>][validation][rut]" value="true">
<label><?php el('RUT'); ?></label>
</div>
</div>
I strongly suggest adding a specific mask for the RUT to avoid problems with the dots and hyphen since THIS validation will ask for them (E.g. 20.234.234-K). This can be easily done by adding this at line 220:
<option value="mask:99.999.999-&">RUT</option>
That's it! Hope it helps someone someday.