Created
October 31, 2019 08:46
-
-
Save JiBrok/56feb2f4510b5b435366329d671df0a8 to your computer and use it in GitHub Desktop.
JiBrok, message field, JavaScript Example: update and hide message with 2 conditions by select fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(['jquery'], function($) { | |
function setCFValue(customfield_id, value){ | |
$('#' + customfield_id).val(value).trigger('change') | |
} | |
function setMessage(title, body, messageType){ | |
var jsonMessage = {}; | |
jsonMessage.title = title; | |
jsonMessage.body = body; | |
jsonMessage.messageType = messageType; | |
setCFValue(CF_ID_MESSAGE, JSON.stringify(jsonMessage)) | |
} | |
function getFieldValue(fieldId) { | |
return $('#' + fieldId).val() | |
} | |
//EDIT HERE | |
var CF_ID_MESSAGE = 'customfield_10017'//set custom field id(Message field) | |
var CF_ID_SELECT1 = 'customfield_10015'//set custom field id(Select field) | |
var CF_ID_SELECT2 = 'customfield_10016'//set custom field id(Select field) | |
var OPTION_ID_HIGH = '10000'//set option id(view in select field config - CF_ID_SELECT1) | |
var OPTION_ID_AFFECTED_ALL_USERS = '10003'//set option id(view in select field config - CF_ID_SELECT2) | |
updateMessage() | |
$('#' + CF_ID_SELECT1).on('change', function(){updateMessage()}) | |
$('#' + CF_ID_SELECT2).on('change', function(){updateMessage()}) | |
function updateMessage(){ | |
if(getFieldValue(CF_ID_SELECT1) === OPTION_ID_HIGH && getFieldValue(CF_ID_SELECT2) === OPTION_ID_AFFECTED_ALL_USERS){//or replace on your options | |
setMessage('High!', 'text for High and Affected all', 'error')//set message config | |
} else { | |
//empty message not showing | |
setMessage('', '', '') | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment