Set value of dropdown to variable in SugarCRM - javascript

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.

Related

AEM Form: Change access control of textfield

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"
}

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.

Input objects not shared across html files

I'm using jsPsych in behavioral research. The developer of that library is very helpful, yet also busy, so I wanted to try and see if the stack overflow community could help me out with a more general js problem :)
In the instance where I'm getting issues, I push objects into an empty array to update the site after input. In this particular case, I use a script that allows me to use external html pages. My problem is, that, while this function here works in order to correctly display a java prompt when assessing a checkbox
var check_consent = function(elem) {
if ($('#consent_checkbox').is(':checked')) {
return true;
}
else {
alert("If you wish to participate, you must check the box next to the statement 'I agree to participate in this study.'");
return false;
}
return false;
};
this here doesn't work in order to assess a text box
var inp = $("#ctry_box").val();
var check_sociodemo = function(elem) {
if ($.trim(inp).length > 0) {
return true;
}
else {
alert("Please fill out the form.");
return false;
}
return false;
};
More specifically, the prompt does actually work, but no matter what you type into "ctry_box", you can't continue the page and the prompt is shown no matter what the input.
Further, the developer set "data" as a object property designed to store data in accordance with individual variable choices. Regarding the same html files, I would like to gather the input from another text box like this
var sociodemo_block = {
type: 'html',
pages: [{url: "text/sociodemo.html", cont_btn: "end", check_fn: check_sociodemo}],
data: [{age: age_box.value}],
force_refresh: true
If I run this, the console tells me that age_box is not defined. Yet again, #consent_checkbox did work. Am I missing something fundamentally here or are the variables simply not shared across the files properly?
I'm very thankful for any help!

Force a SaveForm in Dynamics CRM 2011 using JavaScript

In CRM 2011, I want to be able to force a save of a form. My requirement is as below.
When the user opens the form, I check if a particular field is empty or not.
If it is empty, I want to force a save, thereby triggering a plugin which will set the field.
My current code is as below. This is in the FormOnLoad function which is associated with LoadForm.
if(checkfield == null){
Namespace.Functions.Contact.FormOnSave();
}
else{
// do nothing.
}
Now, this fails with the following line
Can't execute code from a freed script.
I have no clue as to how to proceed further. As a temporary fix, what I have done is the following
if(checkfield == null){
setTimeout('Namespace.Functions.Contact.FormOnSave()',4000);
}
else{
// do nothing.
}
Any advice on why this is happening and how can I fix it without the timeout would be really helpful?
I have had a look at this question and this, but in my case the form does get loaded or has it actually not yet loaded?
Either way, how can I force a save of a CRM form?
You can save the Form by using:
parent.Xrm.Page.data.entity.save();
But It will only trigger if
(Xrm.Page.data.entity.getIsDirty() == true)
However there is a workaround to set IsDirty property true.
Run the Javascript function on PageLoad. Try to update the value of the field which you are planning to populate through plugin:
For e.g.
function OnPageLoad()
{
var yourField = Xrm.Page.getAttribute("new_yourfield").getValue();
if(yourField == null)
{
parent.Xrm.Page.getAttribute("new_yourfield").setValue("any value");
parent.Xrm.Page.getAttribute("new_yourfield").setSubmitMode("always");
parent.Xrm.Page.data.entity.save();
}
}
You could skip all of this mumble jumbo with loading your form twice with Javascript by creating a plugin registered on the read or the entity. (Or better yet and if possible, on the Create of the entity)
The Plugin would just check for the field, and if it's empty, perform whatever logic you need it to to update the field, then save it, and return the updated field (or possibly just populate the value and don't update the database until the user performs the save)

change some tinymce behaviour (javascript)

Hi everybody
I am using the tinymce format dropdown to apply custom styles to html elements. This is for users without html knowledge
One annoying thing for me is that when a user klicks at different styles they all get added and something like this may happen
<div class="floatleft floatright positionup positiondown">
In order to prevent this I searched for the responsible code which is in editor_template.js (compressed) but visible in editor_template_src.js
Is there maybe a way to rewrite this piece of javascript so that each applied style replaces the former?
_createStyleSelect : function(n) {
var t = this, ed = t.editor, ctrlMan = ed.controlManager, ctrl;
// Setup style select box
ctrl = ctrlMan.createListBox('styleselect', {
title : 'advanced.style_select',
onselect : function(name) {
var matches, formatNames = [];
each(ctrl.items, function(item) {
formatNames.push(item.value);
});
ed.focus();
ed.undoManager.add();
// Toggle off the current format
matches = ed.formatter.matchAll(formatNames);
if (!name || matches[0] == name)
ed.formatter.remove(matches[0]);
else
ed.formatter.apply(name);
ed.undoManager.add();
ed.nodeChanged();
return false; // No auto select
}
});
How about:
if (!name || matches[0] == name)
ed.formatter.remove(matches[0]);
else
ed.formatter.remove(matches[0]);
ed.formatter.apply(name);
Just a wild guess, haven't tried it myself.
This a lot of work to do, but it can be done.
I solved this issue writing a custom plugin and using a custom FormatterClass.
I suggest you try developing with tiny_mce_dev.js - this way you are able to track down problems to js classes.
Then you should have a look at the js-class Formatter.js and try to modify this one in order to fullfill your wishes.
The next step will be to save the mofied Formatter.js and make it part of your plugin, so that you can reset the real Formatter.js, cause i suggest not to change the tinymce core files.

Categories