I am writing a device driver with several text preference inputs using the required : true option. An asterisk appears next to the preference in the UI, however it is possible for the respective preferences to be saved with null values. No warning appears as is the case with enum input types??
It's not possible to save but I'm guessing you have null values because you had the device created already and then added the preferences to the driver after the device was already created. Required prevents the save from going through until you've given the preferences values.
Perhaps I've misunderstood you, or I've done a bad job of explaining the question.
In the example above, I'm allowed to save preferences for Dimmer IP Address when it is empty, despite it being a mandatory field i.e. required: true. I have found this to be the case for all string type inputs
I just showed the Automatic Refresh Interval field to highlight that it works for enum type inputs.
I think what @codahq was saying is this.
If you already had an instance of the driver created before you finished coding the preferences section, it might explain your issue.
Try creating a new instance of the driver to see if the required:true is respected.
@stephack I just gave this a go, and am getting the same result. I recreated a new driver using the simplified code below, and then tested with a new virtual device. Still allows me to save preferences with null value in input field.
If you have time, I'd be curious if you get the same result.
Cheers
/**
* Debug Input Driver
*
* Github: Mark Collins (Technomorph303)
* Date: 2020-01-15
*
* Copyright 2020 Mark Collins
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
* Change Log:
*
* 1.0.0 - Initial release
*
*/
metadata {
definition (name: "Debug Input Driver", namespace: "Technomorph303", author: "Mark Collins", importUrl: "") {
capability "Actuator"
capability "Sensor"
capability "Switch"
capability "SwitchLevel"
}
preferences {
input name: "IPAddress", type: "string", title: "IP Address:", required: true
}
}
def installed() {
log.info "Device installed."
}
def uninstalled() {
log.info "Device uninstalled."
}
def updated() {
log.info "Device updated."
}
def on() {
}
def off() {
}
def setLevel (level) {
}
def setLevel (level, duration) {
}
Just checked one of my drivers. I can delete the value in it (this field is required and of type "number") and then click on "save preferences" and it then executes my updated method even though the value was null.
The * should prevent the "save preferences" from working if no value is present.
On the commands though (boxes at the top) required fields are respected and I get a prompt.
I did get the same result.
I also went back into my previously built drivers (that use the "text" syntax that @srwhite suggested) only to realize that they also do not respect the required option. I'm not sure if this has always been the case or if something changed in a recent build because I dont think I ever tested this in any of my drivers. It has always worked in my apps so I assumed it worked in my drivers.
@chuck.schwer is this expected behavior....required:true seems to only be respected in apps and not drivers.