This article introduces the Show DoW (Day of the Week) Plug-in, which is a plug-in version of the sample code introduced in the "Show day of the week on Date fields" article.
This plug-in displays the day of the week next to the specified Date field. The text to display next to the date field can also be modified - for example, the user can choose to show Sunday to be displayed as "Sunday" or "Sun".
The packaged sample plug-in zip file can be downloaded from the Releases page on GitHub.
Install the plug-in into your domain by following the plug-in installation guide on the Help page.
You can then add the plug-in to a specific App by following the plug-in adding guide on the Help page.
To set up the plug-in, the Kintone App must first have a Date field in its form.
The first setting on the setting page specifies which Date field will display the day of the week next to it's Date value. The rest of the settings allows the user to choose what characters will be displayed to represent the day of the week.
The day of the week will be displayed in brackets next to the Date value, after saving the record and displaying the Record Details page.
The sample codes used in the plug-in are listed under the src file in our Github repository.
The plug-in is created with the following file structure:
│ └──── config.html
│ ├──── 51-modern-default.css
│ └──── config.css
│ ├──── config.js
│ └──── desktop.js
│ └──── dowicon.png
This file builds the HTML of the plug-in settings page.
Each <div> tag with the "block" class represents 1 row of related HTML elements.
The first "block" contains the HTML of the first settings, where the user chooses which Date field to display the day of the week next to. A select tag is stated, that creates a drop-down field with a value of -----. This drop-down field is later populated by the config.js file.
The second "block" contains the HTML of the second settings, where the user chooses the text to display for each day of the week. 7 text input fields are placed in for the 7 days of the week.
Both the drop-down field and the input text fields have ids allocated to them, so that they can be controlled by the config.js file.
This CSS file is provided on Github. This file styles HTML elements on the plug-in config page to fit in with Kintone's UI.
We recommend that you do not make changes to 51-modern-default.css. If you need to style additional elements, or over-ride the default styles, those changes should be added into config.css.
This supporting CSS file is used to style some areas of the plug-in config page that 51-modern-default.css doesn't cover.
This file is used to populate the drop-down fields on the plug-in config page, and to also save the data inputted by the user.
Depending on the endpoint called, Get Form Fields can return either the deployed form fields (the user has clicked Update App in the App Settings and the changes have been committed) or the preview form fields (the form has been saved in the App settings, but the user has not clicked Update App and committed them). This function uses the preview endpoint as users may access the plug-in settings page before they are ready to commit their changes.
As this plug-in requires to only use the Date fields from the Get Form Fields response, the fields with type value of DATE (the Date field) are extracted from the object. The extracted selection is then appended to the element with the id of select_date_field (stated in config.html) to make a drop-down list of Date fields in the App.
At the end of the setDropDown function, the code looks through the CONF object where any saved setting data are stored. If it's the first time for the user to use the plug-in, there are no saved values, thus no values are placed in the settings. If the user has saved any settings before in the plug-in (which is stored using Kintone's setConfig API), then those saved values (the specified Date field and the text to display for the days of the week) are inserted into the designated plug-in settings.
Date retrieved with the kintone.plugin.app.getConfig(PLUGIN_ID) method are allocated to variables in the code when the record details page loads (when the app.record.detail.show event triggers). The rest of the code in desktop.js is mostly the same as the code in the "Show day of the week on Date fields" article.
The manifest file states the paths of the files that will be used in the plug-in. It also links to the jQuery library hosted on the Kintone CDN, so that it can be called on the config page.
The array in the value of the required_params key states which settings in the plug-in config page are required. If these settings are not saved using the setConfig API, errors will be displayed on other pages of the App, stating that the plug-in settings have not been configured yet.
The name, description, and homepage_url key-value pairs are labels and links displayed in the plug-in settings.
This plug-in is open sourced under the MIT License. It allows open- or closed-sourced distribution, including commercial use.
If you would like to add more functionality to the plug-in, you are welcome to clone our repository to make your own changes and redistribute it. We generally do not accept external pull requests for the sample plug-in as this repository exists for educational purposes.
If you have any questions related to building Kintone plug-ins, please post your question in the kintone developer network community.