Is there is some way to apply mask on fields in crm 2013 on forms, using any jQuery and jQuery mask plugins.
I read from http://taoofcrm.com/2011/05/19/crm-field-masking-with-jquery/
but it not worked for me on Dynamic crm 2013.
In crm 2011 input field ID is the name of attribute, while in crm 2013 input field ID is the name of attribute plus "_i" (may be "i" denote an input).
So if we have attribute name "name" then input field ID for this attribute in 2011 is "name" and in 2013 it is "name_i".
Following is the Source view of input field of an attribute on the form in crm 2011 and crm 2013.
Input field in crm 2011
<input id="name" tabindex="1010" class="ms-crm-Input ms-crm-Text" style="-ms-ime-mode: auto;" type="text" maxlength="255" value="test" attrformat="text" attrpriv="7" attrname="name" req="2">
Input field in crm 2013
<input id="name_i" title="" class="ms-crm-InlineInput" aria-labelledby="name_c name_w" style="-ms-ime-mode: active;" type="text" maxlength="160" attrname="name" attrpriv="7" controlmode="normal" defaultvalue="Blue Yonder Airlines (sample)">
If you applying masking in crm 2011, then please see here!, or just use following code.
//Include jquery and jqueryMask plugin file on form you apply masking.
function Mask(field, format)
{
$("#"+field).mask(format);
}
// call this function on form load event
function maskFields()
{
Mask("address1_postalcode", "99999-9999");
Mask("telephone1", "(999) 999-9999");
Mask("telephone2", "(999) 999-9999");
Mask("fax", "(999) 999-9999");
}
For crm 2013 you should attach "_i" with field name like.
function Mask(field, format)
{
$("#"+field+"_i").mask(format);
}
But also still not working because in crm 2013 input fields are created on execution time.
you should apply masking on click event of input, or just got focus of attribute before apply masking e.g.
//Include jquery and jqueryMask plugin file on form you apply masking.
function Mask(field, format) {
//first check whether attribute exist or not
var oCtrl = Xrm.Page.getControl(field);
if (oCtrl != null) {
oCtrl.setFocus(true);
$("#" + field + "_i").mask(format);
}
}
// call this function on form load event
function maskFields()
{
Mask("address1_postalcode", "99999-9999");
Mask("telephone1", "(999) 999-9999");
Mask("telephone2", "(999) 999-9999");
Mask("fax", "(999) 999-9999");
}
Worked well for crm 2013.
Related
How do I create a template four user input? The requirement is to have an input text box display something line '0000-0000-00" to get a 10 digit number from a user that will be stored in the data base with out the '-'. This is for the aspnet core 3.1 Razor page.
In the view you add a placeholder to the input tag:
<input asp-for="MyProperty" placeholder="0000-0000-00"/>
You decorate the property MyProperty with an regex data annotation:
[RegularExpression("^([0-9]{4})-([0-9]{4})-([0-9]{1})$", ErrorMessage = "Invalid input")]
public string MyProperty{ get; set; }
I have a page with many required fields. So when I click submit button required validation is firing for the first field then the second then the third and so on...
What I need to do here is , When I click on submit I have to show all errors on a page in one shot.
My requirement is to achieve this only by validating client side.
I am using an .Net core MVC application.
Below is the screenshot of my page
Can I achieve this.. Please help me..
Thanks !!
I can give you an idea to do your job using jquery custom validation.Please refer my solution.
Add custom style class to your required fields.
Example :
<input type="text" class="req-cls" >
Write Jquery function to Check Validation
$(document).ready(function () {
$('#btn1').click(function (e) {
var isValid = true;
$('.req-cls').each(function () {
if ($.trim($(this).val()) == '') {
isValid = false;
$(this).css({
"border": "1px solid red",
"background": "#FFCECE"
});
}
else {
$(this).css({
"border": "",
"background": ""
});
}
});
if (isValid == false)
e.preventDefault();
});
});
See Example here : https://jsfiddle.net/Shalitha/q2n8L9wg/24/
Just add this line in your .cshtml
<div class="validation-summary-valid" data-valmsg-summary="true">
<ul>
<li style="display: none;"></li>
</ul>
</div>
Since you need client side we are talking about JS. But with razor you can validate a few results using the model annotations. For example let's say you have this object.
public class UserCreationVO
{
[Required]
[StringLength(255)]
public string Username { get; set; }
}
Now what you need to do in your frontend (meaning your .cshtml file) is to tell asp.net to use this properties to validate. So for example:
#model UserCreationVO
<form method="post">
<input asp-for="UserName" />
<span asp-validation-for="UserName"></span>
</form>
As you can see above using asp-for is a great way to create validations using your models. Be careful you must pass as a model the object you want to validate. The asp-for tag shows a model property. So you can't pass it in a Viewbag or something. This produces some automatic html and js for you and handles it.
Furthermore you should always validate the result nevertheless in the controller. Because client side validation is for performance reasons and user experience and doesn't offer any kind of security:
public IActionResult CreateUser(UserCreationVO user)
{
if(!ModelState.IsValid)
return your_error;
}
Last but not least: You must include the JQuery unobtrusive validation library. Furthermore if you have some extra requirements like checking if a username exists (Which can't be done without contacting the server) then you can use the [Remote] attribute.
More info and reading about front-end validation with razor: here
How to use a remote attribute: Using remote validation with ASP.NET Core
EDIT:
So generally I advise to use models and create them. As you say policy is required in one form but not in another. What you should do to have a maintanable code where you simply change the attribute of your model and the validation happens you need to create a different VO. For example:
public class CreatePolicyVO
{
[Required]
public string PolicyNumber {get; set;}
}
And another object for example updating:
public class UpdatePolicyVO
{
public string PolicyNumber {get; set;}
}
Because you also need to validate them in the controller. So passing a different object allows you to use ModelState.IsValid and other MVC and razor features. Generally if a field is required in one case and not in another then you need a different model.
First, we need to add the JQuery,jquery.validate & jquery.validate.unobtrusive in our views.
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.16.0/jquery.validate.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validation.unobtrusive/3.2.6/jquery.validate.unobtrusive.min.js"></script>
Then in View add required data-* attributes like:
<label for="Name">Name</label>
<input type="text" data-val="true" data-val-length="Length must be between 10 to 25" data-val-length-max="25" data-val-length-min="10" data-val-required="Please enter the name" id="Name" name="Name" value="" />
<span class="field-validation-valid" data-valmsg-for="Name" data-valmsg-replace="true"></span>
<br />
You could see that it has added the several attributes starting with data-*.
The data-* attributes are part of the HTML5, which allow us the add extra information (metadata) to the HTML element.
The Javascript unobtrusive library reads the data-val attributes and performs the client side validation in the browser when the user submits the form. These Validations are done before the form is sent over an HTTP. If there is a validation error, then the request will not be sent.
I was trying to find a way to implement Input Mask by passing custom attribute from Model Class in MVC ASP NET Core and built HTML attribute accordingly into HTML element .below is the answer
I would like to share with you on how you apply the Input Mask using DisplayMetadata Provider as it is different than other version.
Here are brief steps more info on this can be find it in this link: In MVC Core Passing custom attribute from Model class to HTML element "e.g.:Input Masking" https://www.codeproject.com/Tips/1243346/In-MVC-Core-Passing-custom-attribute-from-Model-cl
1- Create Custom Attribute e.g.:HTMLMaskAttribute , inherit from Attribute Class
2- Create custom DisplayMetadataProvider by implementing the interface IDisplayMetadataProvider , this provider will read the new attribute from the model class .
3-register CustomMetadataProvider in the startup class of MVC application
4-In Model Class add the new custom attribute "mask" in the property you need to create a mask of it example Phone number.
5- I am using Masked Input Plugin for my example download it and include the jQuery and masked input javascript files to your specific view page or to your _Layout.cshtml page .
6- add this script into your view either _layout.cshtml or specific view :
<script type="text/javascript">
$(function () {
$('[mask]').each(function (e) {
$(this).mask($(this).attr('mask'));
});
});
</script>
7- create the view and include the Property that has an attribute
8- Run the application and notice the html attribute mask has been added for to the property Phone1
<input name="Phone1" class="form-control valid" id="Phone1" aria-invalid="false" type="text" value="(123) 456-7890" mask="(999) 999-9999">
Good Day
Hi i have developed a small log in screen in MVC whenever i press submit button it always offers me whether
do you want to save password
i want to disable that option
i can disable that setting from browser
Is it possible to do it using java script or through c#
i tried to set the text box property auto complete=off but it does not work it is still saving password
i even tired to set the property of form tag to auto complete=off
but even that does not work
#Html.TextBoxFor(model => model.UserName, new { #class = "Login_txtType", #maxlength = "50", autocomplete = "off" })
This is now part of HTML5, and according to that standard you can add autocomplete='off' to the form tag then autocomplete='off' will be applied to all fields within the form.
Example :-
<form id="form1" method="post" autocomplete="off">
I am developing a Hybrid application in IBM Worklight .Since i am a newbie in Worklight and Dojo its just a sample application that takes text input value and displays in Alert.I have created a text box, but cant access text box value from javascript function.
My code
<input data-dojo-type="dojox.mobile.TextBox" id="sampleText" placeHolder="NewYork,USA">
<button data-dojo-type="dojox.mobile.Button" id=testBtn style="float:right;" data-dojo-props="label:'GetData', onClick:function(e){getDataInfo();}" ></button>
js Function
function getDataInfo(){
var city = dojox.byId("sampleText").value;
alert(city);
}
Any help is appreciated.
There are 2 solution.
Edit the function:
function getDataInfo(){
var city = sampleText.value;
alert(city);
}
or add dojo-id to textBox
data-dojo-props='id:"sampleText"'>
and use this function
dojox.byId("sampleText")