drupal 6 - unset previously set cck field validation error messages - drupal-6

How can I unset previously set cck field validation error messages? Some module is setting the form validation messages, that I want to override. In my case, it's cck_phone module.
Something like form_unset_error($field['field_name']) to unset the error messages?

one way to unset the error is unset($_SESSION['messages']['error']['cck field']).
But i dont know whether it is the best way to do or not .

You need to delete the errors then clear 'drupal form static cache' if it is the last error.
form_set_error(NULL, '', TRUE);
in order to reset the state of the form. e.g.
$found_error = array_search('This e-mail has already been taken by another user.', $_SESSION['messages']['error']);
if ($found_error !== FALSE) {
unset($_SESSION['messages']['error'][$found_error]);
if (sizeof($_SESSION['messages']['error']) == 0) {
unset($_SESSION['messages']['error']);
form_set_error(NULL, '', TRUE);
}

Related

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

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

Read Only Form Filling - PDFTron

I'm using WebViewer [1] from PDFTron to fill Form Fields in a PDF on Web [2]. There's a way to make some fields in Read Only Mode, so the user will not be able to add text to textfield, check the checkboxes?
I found this page on the documentation [3] but it seems that I can only set document in read only mode, instead I want only custom fields in read only, users will be able to fill some fields and not others.
I found also this page [4] on doc to set fields to readonly but in my case on WebViewer it doesn't work, in my browser the viewerLoaded events never get called; I tried to put the code in another part of the code but nothing happens.
Are there some hints or some working code that you guys use?
Thanks, Alberto
[1] https://www.pdftron.com/webviewer
[2] https://www.pdftron.com/pdf-sdk/form-filler
[3] https://www.pdftron.com/documentation/web/guides/annotations/annotation-permissions?searchTerm=readon#readonly-mode
[4] https://www.pdftron.com/documentation/web/guides/advanced/forms#set-fields-to-readonly
I managed to make it work with a modified version of this code [1]. The final result is:
$(document).on('documentLoaded', function() {
var docViewer = myWebViewer.getInstance().docViewer;
var annotManager = docViewer.getAnnotationManager();
annotManager.on('annotationChanged', function(e, annotations, action) {
// if the annotation change occurs because of an import then
// these are fields from inside the document
if (action === 'add' && e.imported) {
annotations.forEach(function(annot) {
if(annot.fieldName == 'read_only_field_name'){
annot.fieldFlags.set('ReadOnly', true);
}
});
}
});
});
[1] https://www.pdftron.com/documentation/web/guides/advanced/forms#set-fields-to-readonly

How to prevent full refresh using onChange event SSJS

(You may be able to figure out an answer by ONLY reading the last question by itself, but I included everything for reference if necessary)
The onChange of one field is causing displayErrors to show validation results prior to when I need it to do that.
On an xpage, I have these two comboboxes:
1.) locationType
2.) locationEtc
Choices for locationEtc are dependent on what was selected in locationType field.
In the locationEtc field, the choices are using one computed value with this code:
try
{
var locType = getComponent("locationType").getValue();
var key = '';
switch(locType) {
case 'Commuity Service Center':
key = 'loc_cso';
break;
case 'RYDC':
key = 'loc_rydc';
break;
case 'YDC':
key = 'loc_ydc';
break;
case 'HQ':
key = 'loc_hq';
break;
default:
key = 'facilities';
}
var luChoices = #DbLookup('','keywords', key, 'choices');
luChoices.unshift("Select one|''");
return luChoices;
}
catch(e)
{
print("Error:::::"+e);
}
The choices were NOT changing for locationEtc whenever I pick a locationType, but then they do when I add code to clear the location field whenever locationType changes, using a simple action for onChange event of locationType field:
This is great, but when it all refreshes, my displayErrors control appears (yellow background area) showing required field validation results, and a lot of the fields are not filled in yet by design.
How can I make the displayErrors to show ONLY when tying to submit?
Thanks everyone who can help.
Matt
Set disableValidators="true" on the simple action that you created

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',
);
}

Write the plugin when Selecting the lookup flied and according to filed selection Show/Hide Address filed in form.....?

We Have Contact Entities in contact Entitie one lookup filed company Name in that lookup having two values 1.Account and 2.Contact . When we are selecting contact show the address filed when we select account hide the address filed we needs to write the plugin to Execute that works. Kindly any one help me on the same.
Thanks!!
Rajesh Singh
First, if you need to make change on a form, you can't use plug-ins. Plug-ins are made for bussinees logics, like Update another record when the first one is created, make complex logic, etc...
What you need it is a javascript that executes on the OnLoad of the form and OnChange event in that OptionSet.
The lines you are looking for are:
function ShowField()
{
// The field is present on the form so we can access to its methods
var optionSet = Xrm.Page.getAttribute("custom_attribute");
if (optionSet == undefined)
{
return;
}
// The control is present on the form so we can access to its methods
var controlAddress = Xrm.Page.getControl("custom_address");
if (controlAddress == undefined)
{
return;
}
var valueOptionSet = optionSet.getValue(); // This is the value you set creating the OptionSet
switch (valueOptionSet)
{
case 0: // Your account value, show
controlAddress.setVisible(true);
case 1: // Your contact value, hide
controlAddress.setVisible(false);
default:
return;
}
}
You need to register a web resource and register the event, if you need more information about the code or why this stuff is here and why this not just tell me.

Resources