is there any way to start a function only when a lookup field is filled in?
I have some functions that check for the value in the lookup field. This causes this message to appear:
I tried it like this but it doesn´t seems working:
if (fd.field('Division_x0020_lookup').value.Title != 'null'){
isCement();
}
Dear @Sternchen,
The better way to check lookup value is this:
if (fd.field('Division_x0020_lookup').value){
isCement();
}
Lookup fields don't always have Title field, and the null value is not a string. If you want to check it when the form loads, you'll also need to use ready event. More on working with lookup field here - Lookup field — SharePoint forms
if (fd.field('Division_x0020_lookup').value && fd.field('Company_x0020_code_x0020_lookup').value){
changeCurrency();
isCement();
}
But the error appears.
Whats up with this error? How can I handle this?
Due to the error, the other error messages are not displayed.
Do I have to write my functions in the ready function so that they are not executed until the field has been written to? Or how exactly does this work? What is the deal with the alert.
Dear @Sternchen,
I am not sure what the error is - check browser's console for more information. Can you share the rest of the code on the form as well?
But I need to check for a special Title.
Will it work like this?
function isCement(){
if (fd.field('Division_x0020_lookup').value.LookupValue== 'Cement' && fd.field('Selection_x0020_of_x0020_Busines').value == 'Customer SD'){
$(fd.field('Currency').$parent.$el).show();
I tried this but still the same error:
Dear @Sternchen,
This will check for the selected value in the Lookup field as it appears in the field itself.
Try to isolate the error to a specific part of code - remove parts and see where the issue comes from, and then replace the part of the code with LookupValue instead of Title.
I am trying to hind a disable a lookup field if the first lookup field has not been selected yet, but no luck. Can you please advise as it is not disabling the second lookup at all. Please see example of my code below
fd.spRendered(function(){
fd.control('Payroll_Area_2').ready().then(function(control) {
function disableButton() {
if (fd.field('Payroll_Area_2').value.LookupValue == '_')
fd.field('Name').disabled = true;
else {
fd.field('Name').disabled = false;
}
}
// Calling disableComments when the Team Manager Comments value changes
fd.field('Payroll_Area_2').$on('change',disableButton);
// Calling disableComments on form loading
disableButton();
});
})
Dear @Dina_Louw,
One thing is certain here - the Lookup value is never equal to "_", it's a very specific check. Instead, you can try something like this to check that there is no value:
fd.spRendered(function(){
fd.control('Payroll_Area_2').ready().then(function(control) {
function disableButton() {
if (!fd.field('Payroll_Area_2').value)
fd.field('Name').disabled = true;
else {
fd.field('Name').disabled = false;
}
}
// Calling disableComments when the Team Manager Comments value changes
fd.field('Payroll_Area_2').$on('change',disableButton);
// Calling disableComments on form loading
disableButton();
});
})
Sorry just typed too quick. That did not do what I want.
What I want is that lookup 2 needs to be disabled until lookup 1 has a value. When lookup 1 has a value then I want lookup to be enabled. I found a way to disable Expat Name but when I choose an option on Payroll Area it is not enabling my Expat Name now....
Dear @Dina_Louw,
I didn't notice it before, but it's likely because you use fd.control() instead of fd.field() in the beginning.
It should be:
fd.spRendered(function(){
fd.field('Payroll_Area_2').ready().then(function(control) {
function disableButton() {
if (!fd.field('Payroll_Area_2').value)
fd.field('Name').disabled = true;
else {
fd.field('Name').disabled = false;
}
}
// Calling disableComments when the Team Manager Comments value changes
fd.field('Payroll_Area_2').$on('change',disableButton);
// Calling disableComments on form loading
disableButton();
});
})
Try this and check the console again if it doesn't work!