jquery-flexdatalist icon indicating copy to clipboard operation
jquery-flexdatalist copied to clipboard

Cannot automatically or manually set value of input

Open jonhue opened this issue 6 years ago • 12 comments

@sergiodlopes

I tried to automatically set the value of inputs by specifying their value attribute before initializing flexdatalist:

<input class="flexdatalist" value="1" ... />

and I tried to set them manually using JavaScript:

document.querySelectorAll('input.select').forEach( (element) => {
    $(element).flexdatalist( 'value', element.dataset.value );
})

But no avail. I feel like these issues are connected.

I am using version 2.1.4

jonhue avatar Mar 28 '18 08:03 jonhue

ever tried with latest version?

nhaberl avatar Apr 22 '18 20:04 nhaberl

@nhaberl 2.1.4 is the latest version.

jonhue avatar Apr 22 '18 20:04 jonhue

no 2.2.4 ... there are some major changes

nhaberl avatar Apr 22 '18 20:04 nhaberl

@nhaberl Why isn't the NPM package being updated then? https://www.npmjs.com/package/jquery-flexdatalist

jonhue avatar Apr 22 '18 20:04 jonhue

I have downloaded it manually, don't know 22:24, 22. April 2018, "Jonas Hübotter" [email protected]:@nhaberl Why isn't the NPM package being updated then? https://www.npmjs.com/package/jquery-flexdatalist

—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.

nhaberl avatar Apr 22 '18 20:04 nhaberl

@nhaberl I updated to version 2.2.4 and I still experience the same problem.

jonhue avatar Apr 23 '18 06:04 jonhue

@sergiodlopes can you make a sample how to set values programmatically ?

nhaberl avatar May 08 '18 12:05 nhaberl

I'm having what may be a similar issue trying to set the value without success, or at least without immediate effect. Version 2.24, but it's my first time with this plugin so keep that in mind. I'm new to Git too, so forgive me if this is a protocol violation.

This code

var journal = '<?= $journal ?>';
console.log(journal);
console.log($('#journal').val(journal));
console.log(journal == $('#journal').val());

if data-selection-required="true" gives

Drug Test. Analysis
w.fn.init [input#journal.flexdatalist.form-control.flexdatalist-set.flexdatalist-loading]
false

but if data-selection-required="false" it seems to work.

Also, it seems almost like the assignment is delayed, perhaps due to a race condition with loading/parsing a 20K JSON file? With Unicode chars.

FiroStefani avatar May 13 '18 07:05 FiroStefani

@FiroStefani

Using data-selection-required="false" might actually be the problem, I'm using it too.

jonhue avatar May 13 '18 07:05 jonhue

For what it's worth, this code to monitor events:

$('#journal').on('after:flexdatalist.data', function(e, data) {
	console.log('After journals loaded');
	console.log(e);
	console.log(data);
});

shows that the event fires on every keystroke in the #journal field. I had it expected it to fire only once, after the JSON data file for the field is loaded. I thought I might defer the assignment until then, but as it stands, doing...

$('#journal').val('foo')

...inside the event handler triggers the same event leading to stack overflow. Time for plan C ;)

FiroStefani avatar May 14 '18 07:05 FiroStefani

I am using flexdatalist version 2.2.4 and I am not able to set a default value for url. the search in the database is done and even if the data is returned the default value is not set. how to resolve this problem with URL data? because even putting data-selection-required = "false" here does not work. I've sampled documentation with DATA and it worked.

marcipriano avatar Mar 27 '19 14:03 marcipriano

i have the same issue. i want to select value in another flext datalist input based on the value selected in the previous one. can some one help me on this.

savinaga avatar May 12 '19 14:05 savinaga