AEM Form: Change access control of textfield - javascript

I'm using Adobe AEM Form, javascript for scripting.
In my form, I have a drop down which allow the user to pick one of the dropdown value item or to fill the textfield by typing. My script as follows:
Report.Page2.part2.body.subform.Dropdown::exit - (JavaScript, client)
if(this.selectedIndex == "0"){
Textfield.access = "???????"
Textfield.fillColor = "255,255,255"
}
else{
Textfield.rawValue = this.rawValue;
Textfield.access = "readOnly"
Textfield.fillColor = "192,192,192"
}
I am able to change the Textfield to read only, but not able to change it back to writtable. Can someone advice me how to? and other than "readOnly", what other access control can I assign to the textfield.
Thanks!

There is already an accepted answer so just adding a few details on why it works the way it works as suggested in my comments.
TextField.access="literal";
will generate a markup as below
<input type="xxx" literal>
</input>
There are some validations in the framework to check for the allowed values so the literal won't break the HTML over here. The key issues is that this literal is not an attribute so it cannot have a value. For example, the following markup is not possible:
<input enabled="false"></input>
In order to clear the attribute, the only way you can reset it is by using an empty string as below:
TextField.access="";

Report.Page2.part2.body.subform.Dropdown::exit - (JavaScript, client)
if(this.selectedIndex == "0"){
Textfield.access = ""
Textfield.fillColor = "255,255,255"
}
else{
Textfield.rawValue = this.rawValue;
Textfield.access = "readOnly"
Textfield.fillColor = "192,192,192"
}

Related

how to write a js script to make data import from a form error free

I have implemented a HTML webpage which has a form, now I want to add a script to it to load (import) form input given by user and do check if all of it is white spaces and if it is then give error message otherwise proceed. I want to achieve this using Javascript. I could not find the method to do so, I tried disabling the button until length of string is not equal to number of whitespaces, but that doesn't seems efficient.
This worked for me
document.addEventListener('DOMContentLoaded', () => {
// by default submit button is disabled
document.querySelector('#submit').disabled = true;
// Enable button only if there is required text in the input field
document.querySelector('#id1').onkeyup = () => {
var my_string = document.querySelector('#id1').value;
var spaceCount = (my_string.split(" ").length - 1);
if (document.querySelector('#id1').value.length != spaceCount)
document.querySelector('#submit').disabled = false;
else
document.querySelector('#submit').disabled = true;
};
});
You can use HTML5 validation See Link for more info
You can add attributes like required to your html. This also allows you to set custom error messages if the input is not valid.
In JS, you can check if($form.valid)
You can use jQuery to disable the submit button until its valid also.

CRM form edit using Java Script

I am trying to modify a CRM form for an entity called "property".
I want to basically write an IF ELSE statement to do enable/disable a field on the form when the "new property" tab is clicked by the end user on the CRM interface.
I already have written the javascript code but I am not sure of the syntax to create a new property (a new record within the entity)?
I also tried to ID a new property record by the fact the a new property record will have the name field blank.
Please see a sample of the code below:
if(crmForm.all.new_name == null)
{
//Enable field
crmForm.all.new_interestrate.Disabled = false;
}
else
{
//Enable field
crmForm.all.new_interestrate.Disabled = true;
}
I have set this script on the OnLoad section of the form but it is not running. I postulated that this might be because I am clicking create a new property rather than loading an already existing property?
Any feedback would be appreciated.
Thanks
To anyone reading this, I solved my issue, the flaw was that the field wasn't actually null. I basically rectified this problem using the initial statement
var value = crmForm.all.new_name.datavalue
if (value < 1)
{"do something";}
This worked for my case as no name value was less than 1.

Set value of dropdown to variable in SugarCRM

I am fairly new to using SugarCRM and I am just trying to do some validation on a form page I have.
I am simply trying to get the value of my dropdown, and perform my error if it is equal to "None" but I am unsure how to get the value using SugarJS.
Here is an example of how i get just a basic input field, which is working correctly.
var first_name = $('input[name=first_name]').val();
var last_name = $('input[name=last_name]').val();
if (first_name == "") {
$('input[name=first_name]').css({'border':'2px solid red'});
proceed = false;
}
if (last_name == "") {
$('input[name=last_name]').css({'border':'2px solid red'});
proceed = false;
}
See how I make: https://github.com/ErasmoOliveira87/SugarCRM
I create one logic hook to load js files, and use a normal Jquery inside of scripts.js file (I never found other way to do this). This solution I use to professional versions, and works for community too. If you have access to FTP to manipulate the files you just need create the structure otherwise if you using professional version you need to create one package with manifest file(have example in git too).
fields with "_c" are custom fields, you can see the names in studio.
$(document).ready(function(){
$('#account_name').val("Some value");
$('#phone_number').val("Some value");
$('#YOUR_CUSTOM_FIELD_ID_c').val("Some value");
$('#YOUR_CUSTOM_FIELD_ID_c').val("Some value");
});
After create everything you need go to Admin > Repair > rebuild to clean all cache files.

Validation Group

Is it possible to get and control a validation group using javascript? I was able to validate ASPxHtmlEditor if empty or not, but i need to control the validation group. I'm using .net 2.0.
EDITS [04202011]
I need to make ASPxHtmlEditor a required field. I'm using an older version (10.1.6.0) of DevEx (can't update right now), but there is no validation settings for it. I used javascript to validate the editor
function validateEmptyEditor(html)
{
html = html.replace(' ', '');
html = html.replace('<br />', '');
if (html.length < 1)
{
return false;
}
else
{
return true;
}
}
I invoked the function in LostFocus of ASPxHtmlEditor.ClientSideEvents and is working properly. But my page uses validation group for saving. So I need to manipulate validation group when validateEmptyEditor is invoked. Is it possible to control validation group?
If I understand your task properly, you would like to know, whether the controls residing in the ValidationGroup are passing validation or not. If so, this can be done using the following js code:
var isValid = ASPxClientEdit.ValidateGroup("GroupName");
Does this help?

how to extend asp.net application in this scenario

I have asp.net web application.where i am creating the User as registration for a particular Firm.In this firm there are 3 type of user as of now. as Admin, Dealer, Manager. so according to this I am changing the UI page.
Means When Admin (Admin is default entry) going create let say Dealer, then there is different UI except General information fields (like name ,contact details and all). and when creating the manager there is different UI fields, except than General information fields.
To reuse the page i am using this way , when selected Manager then related his UI fields get only visible, same for dealer. obviously there is a dropdown control from where i am selecting User type.
But some how , later on if one more User type get added by firm, I need to generate functionality according to New User type. how can i handle if I don not want to change existing code. sense is how can i write the generic code so that I should not need to change in code behind or in javascript again.
Where as all this things are in planning and under implementation for now. but before to go a head I must clear this thing. I am planning to change the UI structure in javascript as usual way , i means
if selected User Type is "Dealer then make visible these div's ELSE If User Type is Manager then make visible these divs
I want to write generic javacript , though new user type get added.
You could maintain the field <-> user type relation in a database and dynamically add labels and textboxes in the PageLoad of your Page.
Then when a new type of user comes along you'd simply need to add to your data.
Your user type should also be in a database.
Of course, the code that lets your users create other users would also have to be flexible enough. So you'd need a CanCreate table that dictates who can create what type of user. :)
EDIT Expanded how to build your Content
Actually, I like your idea about storing the html elements in the database. That'd save you using reflection to dynamically get the propertyvalue. However, I don't think you'll be able to use databinding and all that.
So instead I'd do something like this:
public enum ControlType
{
Label,
TextBox,
...
}
Make a table something like
UserType
PropertyName
PropertyLabelName
FieldLabelType (int)
FieldContentType (int)
Then on pageload you get the UserType, pull the data from the table, find the div where you want to put the data and then add the controls like:
(pseudocode)
Control label = null;
switch (FieldLabelType)
{
case ControlType.Label:
var label = new Label()
{
.. all kinds of properties
Text = PropertyLabelName
};
control = label;
break;
case ???
...
}
if (label != null)
fielddiv.Add(label);
Control field = null;
switch (FieldContentType)
{
case ControlType.TextBox:
var textbox = new TextBox()
{
.. all kinds of properties
Text = new Binding( ... Path = PropertyName)
};
control = textbox;
break;
case ???
}
if (field != null)
fielddiv.Add(field);
Of course, you'd need to do some positioning to get it all looking pretty. Perhaps chuck in a table or something in code?

Categories