[V3] app.picker.get(el); always returns undefined


#1

I’m using F7 v3.6.7 and app.picker.get(el); always returns undefined. For example, the last line in the code below always shows “undefined”.

		// Check if picker already exists
		var timePicker = app.picker.get(selector_name);
		
		console.log(timePicker);

		if (timePicker === undefined) {

			timePicker = app.picker.create({
				inputEl: selector_name,
				rotateEffect: true,
				formatValue: function (values, displayValues) {
					return displayValues[0] + ':' + values[1];
				},
				cols: [
					// Minutes
					{
						values: (function () {
							var arr = [];
							for (var i = 0; i <= 59; i++) {
								arr.push(i);
							}
							return arr;
						})()
					},
					// Divider
					{
						divider: true,
						content: ':'
					},
					// Seconds
					{
						values: (function () {
							var arr = [];
							for (var i = 0; i <= 59; i++) {
								arr.push(i < 10 ? '0' + i : i);
							}
							return arr;
						})()
					}
				]
			});
		}

		console.log(app.picker.get(selector_name));

#2

It happens because you passes selector of the input, not the selector of picker element to app.picker.get method. You need to save that information somewhere else, for example in input element:

var inputEl = $(selector_name)[0];

// Check if picker already exists
var timePicker = inputEl.f7Picker;

console.log(timePicker);

if (timePicker === undefined) {

  timePicker = app.picker.create({
    inputEl: inputEl,
    ...
  });
  inputEl.f7Picker = timePicker;
}

console.log(inputEl.f7Picker);