Gravity Forms How to set the value of a simple text field at page render - gravityforms

I want to set the value of a simple text field based on the state of another field in a previous page of a form. I am selecting a hosting provider of 'aws' and later in the form, I am asking for the user name.
For aws hosting, I want to force ec2-user to be shown in the text box, so I am using the filter of
add_filter( 'gform_pre_render_4', 'populate_deployment_user' );
function populate_deployment_user( $form )
{
$hosting_provider = rgpost('input_23');
if (strcmp($hosting_provider, "aws") == 0)
{
foreach ( $form['fields'] as &$field ) {
if ( $field->id == 42) {
$field->text = "ec2-user";
}
}
}
}
but the $field->text is not correct. I can't use the gform_field_value_$field_name as that's only called at the start of the form, and not after my other field 23 has been selected.
I'm a newbie in forms, JS and PHP, so floundering somewhat, although I've tried for a couple of days to get a solution.

Solution is to set
$field->defaultValue = "ec2-user";

Related

How to override template file item-list.html.twig for field_slider_images in Drupal 8?

I want to override the item listing template file core/themes/classy/templates/dataset/item-list.html.twig for listing the fields field_slider_images as well as field_blog_tags respectively of their's multiple values of the field.
I have selected "Unordered List" in the view.
Please do check the attached image.
I have created following files :
item-list--field-blog-tags.html.twig
item-list--field-slider-images.html.twig
But, this is not rendered for the listing of the fields.
When I have created item-list.html.twig then only it will access.
However, both fields have different data to style and I am not able to get the current field name which is loading it's data in item-list.html.twig.
Had a brief look at this and it doesn't seem that 'item-list' to have suggestions, which is quite unfortunate.
In this situation there are two options:
Create your own suggestion which would accomplish exactly what you need.
You'll have to do something like this:
/
/*add new variable to theme with suggestion name*/
function hook_theme_registry_alter(&$theme_registry) {
$theme_registry['item_list']['variables']['suggestion'] = '';
}
//send a value to newly added variable to use it build the suggestion
function hook_ENTITY_TYPE_view(array &$build, $entity, $display, $view_mode) {
//add condition here if field exists or whatever, do the same for other field
$build['field_slider_images']['#suggestion'] = 'field_slider_images';
}
//use newly added variable to build suggestion
function hook_theme_suggestions_THEME_HOOK(array $variables) {//THEME_HOOK=item_list
$suggestions = array();
if(isset($variables['suggestion'])){
$suggestions[] = 'item_list__' . $variables['suggestion'];
}
return $suggestions;
}
Now you should be able to use item-list--field-slider-images.html.twig
Second option is to do what others in core did: use a new theme
function hook_ENTITY_TYPE_view(array &$build, $entity, $display, $view_mode) {
//add condition here if field exists or whatever, do the same for other field
$build['field_slider_images']['#theme'] = array(
'item_list',
'item_list__field_slider_images',
);
}

NetSuite SuiteScript Client Side drop down validation

I have a custom form where, in a subtab, I have a dropdown that I need to find out the selected value on the client side after the user selects to perform some validation. I created the script and tied it to the on change event of the dropdown. I cannot seem to find the code to get the selected value on the client side. I have found code to read the value on the server side from a submit event. I need this on the client side on change. I am going to use the ID to look up a record and check a value on that record and if applicable popup a warning to the user. Either SS1 or SS2 is good, whatever would be better I have both available. Any help with this would be great. thanks
In a client script, you can use nlapiGetFieldValue() to retrieve the results.
function fieldchanged(type, name, linenum) {
if(name == 'dropdownid') {
var value = nlapiGetFieldValue('dropdownid');
alert(value);
}
}
OK the nlapiGetFieldValue, did not do the trick, what did was the following
function ValidateField( type, field, linenum ) {
if ( field === 'recordid' ) {
var vendorid = nlapiGetCurrentLineItemValue(type,field,linenum);
var vendorRecord = nlapiLoadRecord('vendor',vendorid);
}
return true;
}
thanks for your help

Kentico 7 hide editable text if it's empty

I have an editable text web part on a page template. It has a custom HTML envelope before and after the text. How can I hide the whole thing, envelope included, if the editable text is empty?
I need to hide it because the envelope adds stylized markup that shouldn't be visible when there is no text.
Can it be done with a K# snippet on the Visible property? I'm unclear how interrogating a document's property works.
Thanks!
Try this as the "Visible" property:
{% (ViewMode != "LiveSite") || (CMSContext.CurrentDocument.editabletext != "") #%}
Change "editabletext" to whatever you have for your web part control ID.
I'm not familiar with Kentico but these solutions might help. They may not address your problem specifically but might aid in a solution.
CMSEditableImage Extension Method
I came up with a way to check this, I added an extension method for
the CMSEditableImage class that takes the CurrentPage PageInfo object
to check the value of the editable region, don't know if this is the
best way or not, but here's the code.
public static bool IsPopulated(this CMSEditableImage editableImage, PageInfo currentPage)
{
bool isPopulated = false;
string value = currentPage.EditableItems.EditableRegions[editableImage.ID.ToLower()].ToString();
if (!string.IsNullOrEmpty(value))
{
value = value.ToUpper();
isPopulated = (value == "<IMAGE><PROPERTY NAME=\"IMAGEPATH\"></PROPERTY></IMAGE>") ? false : true;
}
return isPopulated;
}
via http://devnet.kentico.com/Forums/f19/fp5/t4454/Empty-CMSEditableImage.aspx
JavaScript Method
The webcontainer needs an id, example:
<h2 id="webpart-header">Headline</h2>
Then I have a small javascript function that is attached in an
external js file:
/* Hide Webcontainer via javascript if empty*/
function hideLayer(element) {
elem = document.getElementById( element );
elem.style.display = "none";
}
Now in the wep part configuration, at no data behaviour, you uncheck the checkbox and call the js function by entering following
script in the no record found text: hideLayer("webpart-header");
Whereby webpart-header the id name of your container is. You could
also have a more complex <div> structure here.
via http://devnet.kentico.com/Forums/f22/fp3/t4180/Webcontainer-and-hide-if-no-data.aspx

How to disable validators for a specific field from a button

I have a xpage that loads a Bootstrap modal window (see picture). I need to validate the data only the user pushes the 'Add New' button. I do not want the validators to run when 'Save and Continue' or 'Previous' buttons are pressed.
The modal dialog is a custom control used many times throughout the application. I cannot change the buttons to disable validators because most of the time I want to validate. The center content is stored in its own custom control.
My question is can I add code to the button to get a handle to each control, and set the disableValidators to true. I haven't been able to figure out how to do this. I have already tried computing the disableValidators but was totally unsuccessful. The fields are all bound to scoped variables.
I know that I can use clientside validation here, but the rest of the application uses server-side and I want to be consistent + this is a responsive app, and clientside on mobile is annoying.
Rather than adding code to button to and setting disableValidators for each control I would suggest the other way round. For each control set the required property only if user pushes 'Add New' button.
This blog post by Tommy Valand describes it in detail. The below function lets you test if a specific component triggered an update.
// Used to check which if a component triggered an update
function submittedBy( componentId ){
try {
var eventHandlerClientId = param.get( '$$xspsubmitid' );
var eventHandlerId = #RightBack( eventHandlerClientId, ':' );
var eventHandler = getComponent( eventHandlerId );
if( !eventHandler ){ return false; }
var parentComponent = eventHandler.getParent();
if( !parentComponent ){ return false; }
return ( parentComponent.getId() === componentId );
} catch( e ){ /*Debug.logException( e );*/ }
}
So if you want the validation to run only when the user clicks a specific 'Add New' button then write this in all the required-attributes:
return submittedBy('id-of-add-new-button')

On Orchard CMS, how can I display a message when the query returns no records for a projection

Using the admin panel on Orchard CMS I've created the following:
A content type called CalendarEvent, it contains several fields including the EventDate;
A query that has 2 filters, one by the content type (= CalendarEvent) and another one based on the date of the event. The Display Mode on the Layout is set to Properties;
A projection to display the query when a menu item is clicked.
The problem is that based on the EventDate we only display upcoming events, not the ones in the past. If for some reason there are no events to be displayed, all the user gets is an empty page with no information whatsoever.
My question is, how can I modify my query or projection in order to display something like: "There are no current events scheduled"?
I know the Properties on the Query's Layout allow me to specify a "No Result", but this implies that a record is present and that the actual property is empty. However, in my example, no record is present.
Thank you all in advance.
Rafael
By the way, I am using the latest Orchard version 1.6.
What I have done is to create a shape and use it as a view in my query. The shape will then have an if statement to check if the query return gives any results.
Example:
#using Orchard.ContentManagement
#using Orchard.Utility.Extensions
#{
var dealsTerms = ((IEnumerable<ContentItem>)Model.ContentItems).ToList();
}
#if (dealsTerms.Any() )
{
<div>
#foreach (var dealTerm in dealsTerms)
{
var contentManager = dealTerm.ContentManager;
<div>
#Display(contentManager.BuildDisplay(dealTerm, "Summary"))
</div>
}
</div>
}
else
{
<p>No deals found</p>
}
I used this article as reference:
http://www.ideliverable.com/blog/ways-to-render-lists-of-things
Good luck
If your projections are Layouts elements, you can create a Projection.cshtml file in your theme's Views/Elements folder with the following:
#{
var list = Model.List;
var pager = Model.Pager;
if (list != null)
{
#Display(list)
if (list.Items.Count == 0)
{
<div>There are currently no items.</div>
}
}
if (pager != null)
{
#Display(pager)
}
}
This is a copy of the default template with the if (list.Items.Count == 0) section added. Edit as needed.

Resources