Creating your own Autocomplete Form plugin
You can create your own autocomplete form.
Conditions:
- The new Autocomplete Form Values class must implement the “AutocompleteFormValues” interface.
- The new Default Form Values class must be declared in the package “com.openkm.plugin.form.values”.
- The new Default Form Values class must be annotated with “@PluginImplementation”.
- The new Default Form Values class must extend “BasePlugin”.
AutocompleteFormValues interface:
package com.openkm.plugin.form.values;
import com.openkm.bean.form.*;import net.xeoh.plugins.base.Plugin;
import java.util.List;import java.util.Map;
public interface AutocompleteFormValues extends Plugin { String getName();
void autocomplete(String uuid, String grpName, List<FormElement> formElementList);
/** * Helper method to autocomplete form elements with provided properties. * Sets matching values on Input, CheckBox, TextArea, SuggestBox, and Select elements. */ default void autocompleteHelper(List<FormElement> formElementList, Map<String, String> props) { // ... default implementation provided by the interface }}The new class must be loaded into the package com.openkm.plugin.form.values because the application’s plugin system will try to load it from there. See the sample below:
Method description
Section titled “Method description”| Method | Type | Description |
|---|---|---|
| autocomplete(String uuid, String grpName, List |
void | The method autocompletes the group’s form elements. |
Example of the autocomplete form values implementation
Section titled “Example of the autocomplete form values implementation”package com.openkm.plugin.form.values;
import com.openkm.bean.form.FormElement;import com.openkm.bean.form.HorizontalPanel;import com.openkm.bean.form.Input;import com.openkm.bean.form.VerticalPanel;import com.openkm.plugin.BasePlugin;import lombok.extern.slf4j.Slf4j;import net.xeoh.plugins.base.annotations.PluginImplementation;import org.apache.commons.lang3.StringUtils;
import java.util.List;
@Slf4j@PluginImplementationpublic class SampleAutocompleteFormValues extends BasePlugin implements AutocompleteFormValues { @Override public String getName() { return "Sample autocomplete form values implementation"; }
@Override public void autocomplete(String uuid, String grpName, List<FormElement> formElementList) { log.info("autocomplete({}, {}, {})", uuid, grpName, formElementList); autocompleteValues(formElementList); }
private void autocompleteValues(List<FormElement> formElementList) { for (FormElement formElement : formElementList) { if (formElement instanceof Input input) { if (Input.TYPE_TEXT.equals(input.getType()) && StringUtils.isEmpty(input.getValue())) { input.setValue("Autocomplete with name: " + formElement.getName()); } } else if (formElement instanceof HorizontalPanel hPanel) { autocompleteValues(hPanel.getElements()); } else if (formElement instanceof VerticalPanel vPanel) { autocompleteValues(vPanel.getElements()); } } }}Metadata definition
Section titled “Metadata definition”<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 3.11//EN" "http://www.openkm.com/dtd/property-groups-3.11.dtd"><property-groups> <property-group label="Autocomple sample" name="okg:autocomplete" autocompleteValueClassName="com.openkm.plugin.form.values.SampleAutocompleteFormValues"> <input label="Input label first" name="okp:autocomplete.first" type="text"/> <hpanel name="okp:autocomplete.horizontal1"> <input label="Input label 1" name="okp:autocomplete.input_h1" /> <input label="Input label 2" name="okp:autocomplete.input_h2" /> </hpanel> </property-group></property-groups>Metadata Extraction using AI
Section titled “Metadata Extraction using AI”If a document contains extracted text and the artificial intelligence parameters are properly configured in the OpenKM application settings, metadata can be automatically extracted using the following autocomplete plugin:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 3.11//EN" "http://www.openkm.com/dtd/property-groups-3.11.dtd"><property-groups> <property-group label="Consulting" name="okg:consulting" autocompleteValueClassName="com.openkm.plugin.form.values.AIAutocompleteFormValues"> <input label="Input label" name="okp:consulting.input1" /> <separator label="Separator label" name="okp:consulting.separator" /> <input label="Input label" name="okp:consulting.input2" /> </property-group></property-groups>