Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form field default value (for select input only) #380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public enum Source
@Builder.Default
private Map<String, String> selectOptions = Collections.emptyMap();

@Builder.Default
private String defaultValue = "";

@Builder.Default
private List<String> mimeTypes = Arrays.asList(
"image/gif",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ Tooltip_FormOptions_LinkLabel=Label to be displayed that tells where the link wi
Tooltip_FormOptions_LinkURL=Full url that you want to go to when the link is selected.
Tooltip_Form_ShowInNewWindow=Choose if the link will e opened in a new browser window
Tooltip_FormOptions_Placeholder=Placeholder text to display in the form field with the field is not populated with a value.
Tooltip_FormOptions_DefaultValue=Field default value.
Tooltip_FormOptions_Javascript=Javascript to be added to the browser. This option is depreciated. Use 'Settings -> User Interface -> Look & Feel -> Embedded JavaScript' instead.
Tooltip_FormOptions_MultiValue=Display multiple values of the attribute.
VerificationMethodDetail_PREVIOUS_AUTH=This method is passed when a user has previously authenticated using their browser. There is no user interaction or display associated with this method.
Expand Down
11 changes: 10 additions & 1 deletion server/src/main/webapp/WEB-INF/jsp/fragment/form.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@
<% } else if (loopConfiguration.getType() == FormConfiguration.Type.select) { %>
<select id="<%=loopConfiguration.getName()%>" name="<%=loopConfiguration.getName()%>" class="inputfield selectfield" <pwm:autofocus/> >
<% for (final String optionName : loopConfiguration.getSelectOptions().keySet()) {%>
<option value="<%=optionName%>" <%if(optionName.equals(currentValue)){%>selected="selected"<%}%>>
<option value="<%=optionName%>" <%
if (StringUtil.isEmpty(currentValue)) {
if (optionName.equals(loopConfiguration.getDefaultValue())) {
out.write("selected=\"selected\"");
}
} else {
if (optionName.equals(currentValue)) {
out.write("selected=\"selected\"");
}
} %>>
<%=loopConfiguration.getSelectOptions().get(optionName)%>
</option>
<% } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ FormTableHandler.newRowValue = {
labels:{'':''},
regexErrors:{'':''},
selectOptions:{},
defaultValue:'',
description:{'':''},
type:'text',
placeholder:'',
Expand Down Expand Up @@ -288,6 +289,10 @@ FormTableHandler.showOptionsDialog = function(keyName, iteration) {
bodyText += '</tr><tr>';
if (currentValue['type'] === 'select') {
bodyText += '<td class="key">Select Options</td><td><button class="btn" id="' + inputID + 'editOptionsButton"><span class="btn-icon pwm-icon pwm-icon-list-ul"/> Edit</button></td>';
bodyText += '</tr><tr>';
}
if (currentValue['type'] === 'select') { // temporary condition
bodyText += '<td id="' + inputID + '-label-defaultValue" class="key" title="' + PWM_CONFIG.showString('Tooltip_FormOptions_DefaultValue') + '">Default Value</td><td><input type="text" class="configStringInput" style="width:70px" id="' + inputID + 'defaultValue' + '"/></td>';
bodyText += '</tr>';
}
}
Expand Down Expand Up @@ -411,6 +416,12 @@ FormTableHandler.showOptionsDialog = function(keyName, iteration) {
currentValue['javascript'] = PWM_MAIN.getObject(inputID + "javascript").value;
FormTableHandler.write(keyName)
});

PWM_MAIN.getObject(inputID + "defaultValue").value = currentValue['defaultValue'] ? currentValue['defaultValue'] : '';
PWM_MAIN.addEventHandler(inputID + "defaultValue", "change", function(){
currentValue['defaultValue'] = PWM_MAIN.getObject(inputID + "defaultValue").value;
FormTableHandler.write(keyName)
});
}
if (showSource) {
var nodeID = inputID + 'source';
Expand Down