Filepond set plugin properties - filepond

Many Filepond plugins have properties available to modify their behaviour e.g. https://pqina.nl/filepond/docs/patterns/plugins/image-validate-size/#properties.
How do I change them? The Filepond documentation shows how to register a plugin, but not how to customise the properties. I have tried to set them directly on the object:
FilePondPluginImageValidateSize.imageValidateSizeLabelExpectedMinSize = 'Foo';
and looked for a setProperties/setOptions method, which doesn't exist.

You can pass them to the FilePond constructor, for example:
const myInstance = FilePond.create({
maxFileSize: '5MB'
});

Related

Select2 with ajax option

I have been using selec2 version 4 with ajax option.
And I want to set a selected value, as recommended in the guideline, by adding new Option element.
A problem I have is that I do not know when to add the new option because the event select2-loaded does not seem to exist in the latest version of select 2.
Can you please let me know in what way I can know the moment when data has finished loading from the server and has finished setting up, so I can add a new option to it?
Thank you.
The Option element you mention is created by calling the Option() constructor which then constructs a HTMLOptionElement. So basically you are just adding to your DOM and don't need to do it in any select2 event. Instead just do it on document load.
Here's a very basic example of what it could look like:
$(function () {
$('#element-to-select').select2();
var option = new Option('text', 'value', true, true);
$('#element-to-select').append(option).trigger('change');
}
Note that we are calling .trigger('change') to report the change to select2 as documented here.

How to change a CKEditor plugin title in the config.js

Is there a possibility to change the 'title' and/or 'button' property defined in the plugin's lang.js file via the config.js file for a specific plugin?
It is the text which is shown in the dialog title/tooltip and I would like to avoid changing it directly inside the lang.js file. Or would I have to write the devs for a more fitting translation?
Or would I have to write the devs for a more fitting translation?
If you want to change the translation in CKEditor, the recommended way is joining the Transifex translation team - https://www.transifex.com/ckeditor/ckeditor/
You can change the lang entry like it has been presented below (you can put this code inside config.js) but please note this will not be localized thus if your CKEditor supports multiple languages it is better to make this change in lang file directly.
CKEDITOR.on( 'instanceReady', function( ev ) {
console.log( editor.lang.button );
editor.lang.button.selectedLabel = 'xyz';
console.log( editor.lang.button );
});

Need a non-ugly way to dynamically modify acceptFiles and allowedExtensions

I have an uploader that has two modes where it uploads different file types. Which one is active depends on what the user is doing. I am using FineUploaderBasic.
Right now to dynamically modify the allowedExtensions I do something like this:
if(type==<?=Campaign_Placement::AD_TYPE_USER_FLASH?>) // SWF
uploader._options.validation.allowedExtensions = ['swf'];
else // Static image
uploader._options.validation.allowedExtensions = ['jpeg', 'jpg', 'gif', 'png'];
uploader.reset(); // Resets with the new extensions
And to modify the acceptFiles:
if(type==<?=Campaign_Placement::AD_TYPE_USER_FLASH?>) // SWF
$('input[name="userfile"]').attr("accept", "application/x-shockwave-flash");
else // Static image
$('input[name="userfile"]').attr("accept", "image/jpeg, image/jpg, image/gif, image/png");
Both are ugly ways to do this, would appreciate a simple way to do both of these through the API, or some other elegant solution. Thanks!
You have 3 other options to solve this problem:
Don't set the allowedExtensions validation value at all. Then contribute a validate event handler that returns false if the user has submitted an invalid file, based on the value of the select you have provided.
Simply construct or re-construct the uploader instance whenever the user changes their selection.
Consider using the relatively new extraButtons feature, where you can connect additional upload buttons to a single Fine Uploader with varying validation options. For example, you can contribute some default allowed extensions (tied to the default upload button), and then provide an extraButtons button with alternate allowedExtensions. Simply display the appropriate button via JavaScript when the user changes their selection.

How do I use CKEditor's removeMenuItem() function?

I'm trying to remove the 'paste' option from the right-click menu. There is a recently added function which is supposed to do this, but I'm not sure how to call it.
Documentation: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#removeMenuItem
I've tried the following in CKEditor's config.js file, which don't appear to work:
CKEDITOR.editor.removeMenuItem('paste');
CKEDITOR.editor.prototype.removeMenuItem('paste');
config.removeMenuItem = 'paste'; /* in main config array */
Any suggestions? (Removing right-click menu completely is not an option as I need it for table editing)
Why your tests didn't work:
CKEDITOR.editor.removeMenuItem('paste');
The CKEDITOR object doesn't have a property "editor",
CKEDITOR.editor.prototype.removeMenuItem('paste');
Ditto, and trying to get the prototype won't help.
In both cases you have some error messages waiting for you in the error console
config.removeMenuItem = 'paste'; /* in main config array */
As you have linked, removeMenuItem is a method of the editor object, not a property of the config object.
What you can do:
CKEDITOR.instances.editor.removeMenuItem('paste');
The CKEDITOR object has a property "instances" that contains all the instances, so replace "editor" with the name of your editor and it will work. (of course, after the instance has been created, not before)
You can try this, it worked for me
CKEDITOR.instances.contentEditor.config.removePlugins = 'image,resize';
contentEditor is the name of the instance of CKEDITOR.
You can use the config and set removePlugins and pass a string with the name of the property, that you want to remove. But remember it will only work with those property names, that is present in the plugins object. Like if you want to remove 'paste' you have to do this
CKEDITOR.instances.contentEditor.config.removePlugins = 'pastefromword,pastetext';
When creating the editor in array configuration includes:
var config = {...,
                          'removeButtons': 'Maximize'};
by exzemplo

Create base jqgrid

I have a website with several views, and most of them have a jqGrid on them.
I'd like to set some base options on all my jqgrids. For example, I'd like the view option to always be set to true, and the search option to always be set to false.
Additionally, there are several that I'd like to have the same button labels.
Is there any way to do this with a jqGrid?
Look at the answer which shows how to set default settings jQuery.jgrid.nav. In your case it would be
jQuery.extend(jQuery.jgrid.nav,
{search:false,view:true, viewtext:"View label", viewtitle:"View tooltip"}
);
Other default settings you can change in the same way using jQuery.jgrid.del, jQuery.jgrid.view and of course jQuery.jgrid.defaults.
You don't need to place the code inside of jQuery(document).ready(function() {/**/});. It is enough just ecxecute the code like jQuery.extend(jQuery.jgrid.nav, {search:false,view:true}); inside a JavaScript file loaded after the jquery.jqGrid.min.js.
You could add an additional script tag to your HTML that references a JS file with some base configuration stuff for the grid in a $().ready(function() {}); block.
You could also create a base configuration function or variable that you store in that external JS, and reference that configuration on each view page.
I would prefer to write the base function, and not the ready event handler as the ready handler will NOT run at a predictable time. You won't know if it properly ran before your jqGrid configure function ran.

Resources