I have been putting together a form that does a data source lookup to populate some of the fields. I currently have it so someone chooses a School ID and if the Teacher Status = 1 in the table it shows teachers with that status. Next to my status field there is an Auto Fill button that has to be clicked before the teacher information is populated. Is there a way to make the Auto Fill button go away? Why is it there? I plan on hiding the Status field, so I don't want anyone to have to click a button before getting the list of teachers.
Question
Question
Answer
The button appears because you have multiple conditions that must be met before the lookup will happen. There should be a pretty straightforward way around this. Here's an example. The fields that are used in the conditions for the lookup rule are given the lookupCondition class.
$(document).ready(function () { function autofill() { $('.autofill').trigger('click'); } $('.lookupCondition').change(autofill); });
Then you can hide the button using this CSS rule:
.autofill {display: none;}
How would this be used in a table? I have a table where each row requires two drop-down field values to be selected and then calculates a distance. The example above works for the first row, but not additional rows.
I added some handling for tables, let me know if that resolves the issue for you.
function tableAutofill() { $('.cf-table-block tbody tr').each(function () { $(this).find('button.autofill').trigger('click'); }); } function autofill() { $('.autofill').trigger('click'); } $(document).ready(function () { $('.lookupCondition input').blur(autofill); $('.cf-table-block').change(tableAutofill); });
I replaced the code I had with the code you supplied, but it still only fills in the first row, and not the others.
I updated the code example above, let me know if that solves the issue.
That did it! Thank you!
You're welcome!
Eric,
I have this same scenario as Blake except my field in not in a table. I applied your suggested code:
function autofill() { $('.autofill').trigger('click'); } $('.lookupCondition').change(autofill);
and then proceeded to hide to button but for some reason the function is not being fired off when the form starts. I added a windows.alert to verify this.
Any suggestions why this may not be working?
Thanks
Any suggestions?
This is not supposed to work on page load, it is supposed to work when the field given the CSS Class 'lookupCondition' is changed.
Thanks Kenneth, you are right it only fires off when the field is changed.
With that, I used the change to a normal input field to fire off this function.
Thanks for your help.
Replies
Hi Eric,
I am unable to get this to work, I first have JavaScript populate the row number, which you helped me with. I now need it to wait until a position is selected in a drop down and then the auto fill button "pushed". Here is what I have.
$(document).ready(function () {
rowNumbering();
$('#q2').click(rowNumbering);
function rowNumbering() {
currentRow = 1;
$('.cf-table-block tbody tr').each(function () {
$(this).find('.rowNum input').val(currentRow);
currentRow++;
});
}
});
function tableAutofill() {
$('.cf-table-block tbody tr').each(function () {
$(this).find('button.autofill').trigger('click');
});
}
function autofill() {
$('.autofill').trigger('click');
}
$(document).ready(function () {
$('.lookupCondition input').blur(autofill);
$('.cf-table-block').change(tableAutofill);
});
Hi Jessica,
Try this:
$(document).ready(function () { $('#q1 select').change(tableAutofill); rowNumbering(); $('#q2').click(rowNumbering); function rowNumbering() { currentRow = 1; $('.cf-table-block tbody tr').each(function () { $(this).find('.rowNum input').val(currentRow); currentRow++; }); } function tableAutofill() { $('.cf-table-block tbody tr').each(function () { $(this).find('button.autofill').trigger('click'); }); } });
It worked!
Thanks!
You're welcome!
Hi Eric,
I have a drop-down for selecting Organization and a lookup rule to populate 'amount per user' in 6 different tables. I would like to look for an alternative to auto fill button as sometimes the user might not click it.
I've tried making the 'amount per user' fields required, both via Forms as well as javascript, but the form can submitted with no input in them.
Thanks