Jquery Adxstudio Make Date Field Read Only

CRM grade script's (i.e., Onload, OnSave, OnChange) won't run on ADX/Dynamics 365 Entity Form's.

What if we must Get/Ready, Hibernate/Show or Enable/Disable controls based on business logic? We need to write custom script and add in "Custom JavaScript" department of "Entity Form".

Custom Javascript

Custom Javascript

In this article, I am providing syntax'due south to Get/Set attribute values and bones validations.

Get value:

Text Field:

Here 'name' is CRM field's schema name.

  • var contactName=$("#proper name").val();

Await upwardly

  • var lookupGUID = $("#new_contactid").val();
  • var lookupValue = $("#new_ contactid_name").val();
  • var entityName= $("#new_contactid_entityname").val();

Option Set up

  • var userType = $("#new_usertype").val();

DateTime

  • var dobValue= $("#new_dob").val();
  • // Convert to date
  • var dob=new Appointment(dobValue);

Checkbox

Below is the script to determine whether the checkbox is checked or not

var isChecked = $("#{field_name}").is(":checked");
if (isChecked == truthful) {
warning("Checked!");
}
else if (isChecked == fake) {
alert("Unchecked!");
}

Radio Button

Radio button renders equally 2 controls. Below is the syntax to read which radio pick has been checked.

var isOption1Checked = $("#{field_name_0}").is(":checked"); //Returns true/false

var isOption2Checked = $("#{field_name_1}").is(":checked"); //Returns true/false

Set Value:

Text Field

  • $("#name").val("Rajeev Pentyala");

Look upwards

  • $("#new_contactid").val(lookupId);
  • $("#new_contactid_name").val(lookupName);
  • $("# new_contactid_entityname").val(EntitySchemaName);

Option Set

Here 'new_usertype' is CRM field'southward schema proper name.

  • $("#new_usertype").val(10000);

Checkbox

$('#{fieldname}').prop('checked', true);

Radio Button

// To prepare Radio 1 to 'true'

$('#{fieldname_0}').prop('checked', true);

// To ready Radio 2 to 'true'

$('#{fieldname_1}').prop('checked', true);

Date time

Beneath is the snippet to set Date field to 'Today'

// Get today()
var dateValue = new Date();
// Get date field
var dateField = $("#new_mydatefield");
var $displayField = dateField.nextAll(".datetimepicker").children("input");
var dateFormat = $displayField.attr("data-date-format");
dateField.val(moment.utc(dateValue).format("YYYY-MM-DDTHH:mm:ss.0000000\\Z"));
$displayField.val(moment(dateValue).format(dateFormat));

Annotation: Portal uses Moment.js for Date operations.

Annotation

Get/Set statements demand to wrap in Document's Ready event.

$(certificate).ready(function() {
// $("#proper name").val("Rajeev Pentyala");
});

Enable/Disable Controls:

Lookup

  • Information technology'due south very catchy to Enable/Disable Lookup'due south
  • Lookup control return as multiple components on ADX form, to disable lookup pick, we need to find the 'Magnifier' button and Hide it.

$("#new_contactid_name").parent().observe('.input-grouping-btn').hide(); // Observe lookup's Magnifier button and Hide it

Appointment

  • Below is the script to disable 'Engagement' command

// My Date field's schema name is 'new_dateofbirth'
var dateField = $("#new_dateofbirth");
// Go 'Text' field of Date Control
var displayField = dateField.nextAll(".datetimepicker").children("input");
// Get 'Calendar' Icon of Date Control
var dateIcon = dateField.nextAll(".datetimepicker").children("bridge");
// Make 'Text' field of Appointment Command Read-But
displayField.attr("readonly", "readonly");
// Hibernate 'Calendar' Icon
dateIcon.css("display", "none");

Text

  • $("#proper noun").prop('disabled', true);

Hide/Bear witness Controls:

–Selection one
// Hide
$("#fieldname").hide();
$("#fieldname_label").hide();
// Evidence
$("#fieldname").show();
$("#fieldname_label").show();

–Option ii
// Hide
$("#fieldname").closest("tr").hide();
// Show
$("#fieldname").closest("tr").show();

Brand OOB Required Field Non-Required:

  • If the Field is OOB Required or set as Required using Metadata, below is the function to brand field as Non-Required.
    • Note: OOB required field will have the validator naming convention as "RequiredFieldValidator" + fieldSchemaName"
  • Make sure you pass field's Schema Proper name to below function.

function makeOOBFieldNonMandatory(fieldSchemaName){

$.each(Page_Validators, function (index, validator) {

if (validator.id == "RequiredFieldValidator" + fieldSchemaName) {

Page_Validators.splice(index, ane);

}

});

$("#" + fieldSchemaName+ "_label").parent().removeClass("required");

}

  • To ready custom validator, refer this article

Liquid Script Syntax'southward :

  • Get current Portal User (i.e.,Contact) guid

$(certificate).ready(function () {

var portalUserId = '{{ user.Id }}';

});

  • Get current Portal User (i.e.,Contact) Name

$(document).ready(function () {

var portalUserName = '{{ user.fullname}}';

});

  • Check if current Portal User has a specific 'Web Role'

$(document).fix(function () {

{% if user.roles contains 'Administrators'%}
warning("Current portal user has 'Administrators' web role");
{% endif %}

});

  •  Check if User is logged-in or not

{% if user %}

// Logged-In User

{% else if %}

// Not logged In. Anonymous User

{% endif %}

Validations:

Custom Validation on 'Submit'

  • On click of the 'Submit' button a function named webFormClientValidate is executed.

Validation-on-submit

Validation-on-submit

  • We can extend this method to add together our custom validation logic.
  • In below example, I am preventing 'Submit', if Name is non 'Rajeev'

if (window.jQuery) {
(function ($) {
if (typeof (webFormClientValidate) != 'undefined') {
var originalValidationFunction = webFormClientValidate;
if (originalValidationFunction && typeof (originalValidationFunction) == "function") {
webFormClientValidate = office () {
originalValidationFunction.apply(this, arguments);
// Offset custom validation.
// Prevent Submit if Proper noun!=Rajeev
if ($("#name").val() != 'Rajeev') {
render false; // To prevent the form submit return false
}
// End custom validation.
return true;
};
}
}
}(window.jQuery));
}

Refer Adx portal'south blog on Custom JavaScript.

Session Timeout:

Post-obit 2 keys need to exist added to 'Site Settings' entity.

PSession_1

Name : Hallmark/ApplicationCookie/ExpireTimeSpan
Value : The default amount of fourth dimension cookie authentication sessions are valid for. Default: 24:00:00 (i day). To ready 30 minutes interval specify value as 00:30:00.

Proper noun : Authentication/ApplicationCookie/LoginPath
Value : /SignIn
Description: Redirection onto the given login path afterwards session timeout. We tin can configure our own custom Web Template and redirect upward on session death.

Restrict 'File Types' during uploads:

  • To allow specific file types merely, during the uploads from portal, provide configurations specified on screenshot on the portal's 'Entity Form'.
  • Make sure to check the 'Restrict File To Have Types' checkbox.
  • In the 'Accept' field, specify the mimetypes of allowable file types separated by ,
    • image/jpeg,prototype/pjpeg,application/pdf,paradigm/png

RestrictFileTypes

🙂

lewiswarts1960.blogspot.com

Source: https://rajeevpentyala.com/tag/adx-portal/

0 Response to "Jquery Adxstudio Make Date Field Read Only"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel