Rinu
(kannan)
June 24, 2020, 5:04am
1
Hi I would like to show/hide fields based on toggle.
the below code i tried is working if its text field but not for list and library control.
SPDataTable3 is the table i would like to hide
hideOrShow();
function hideOrShow() {
if (fd.field('ProfessionalIndemnityInsurance').value) {
$(fd.container('SPDataTable3').$parent.$el).show();
} else {
$(fd.container('SPDataTable3').$parent.$el).hide(); ;
}
}
fd.field('insuranceclaimslevied').$on('change', hideOrShow);
fd.field('ProfessionalIndemnityInsurance').$on('change', hideOrShow);
Margo
(Margo)
June 24, 2020, 7:22am
2
Hello @Rinu ,
To hide/show List or Library control dynamically you need to:
Give control a CSS class, e.g. 'table-to-hide'
And use this code to show/hide the control:
//hide control
$('.table-to-hide').hide();
//show control
$('.table-to-hide').show();
Please find more information about how to work with fields/control/containers in JavaScript here .
Rinu
(kannan)
June 24, 2020, 7:53am
3
Thank you Mnikitina, was it the same for any controls such as RichText etc
Dear @Rinu ,
Yes, you can use the following method for anything on the form. Moreover, you can give the same class to a number of cells, and hide multiple at the same time, like a group.
Sternchen
(Corinna Knapp)
May 18, 2022, 10:26am
5
Hello @Nikita_Kurguzov ,
is there any way that I can require a file to be uploaded?
Like this:
$('.table-to-hide').required = true;
Best regards
Corinna
Margo
(Margo)
May 18, 2022, 11:17am
6
@Sternchen ,
What field or control do you want to make required?
Sternchen
(Corinna Knapp)
May 18, 2022, 11:48am
7
I want to make the document libary required:
Presumably, however, this is not possible.
I tried to use a attachment but sadly this isn´t working.
Margo
(Margo)
May 19, 2022, 5:43am
8
@Sternchen ,
You can make the List or Library control required by adding a custom form validator:
fd.validators.push({
name: 'MyCustomValidator',
error: 'Upload files',
validate: function(value) {
if (fd.control('SPDataTable1').widget.dataItems().length < 1){
return false;
}
return true;
}
});
Please note that Attachments fields form the Common fields section don't save files to SharePoint site. Files are saved to your Plumsail Account.
Sternchen
(Corinna Knapp)
May 19, 2022, 6:26am
9
It looks like it is not working. I changed the SPDataTable1 to 2.
I have put the valdidator once before the render function and once as in here. However, I can save the form even if no document is uploaded.
Margo
(Margo)
May 19, 2022, 8:02am
10
@Sternchen ,
Try adding the validation after the control is ready like this:
fd.spRendered(function() {
fd.control('SPDataTable1').ready(function(dt) {
fd.validators.push({
name: 'MyCustomValidator',
error: 'Upload files',
validate: function(value) {
if (fd.control('SPDataTable1').widget.dataItems().length < 1){
return false;
}
return true;
}
});
});
});
If that won't work, please share the screenshot of all errors from the browser console(F12).
Sternchen
(Corinna Knapp)
May 19, 2022, 8:31am
11
Here are all the errors:
These are the errors I get, when i hit the save button:
Margo
(Margo)
May 19, 2022, 11:38am
12
@Sternchen ,
These errors are not related to the code I've shared.
Please comment out all code except for the part I've shared and test. Make sure you are using the control internal name in the code.
Sternchen
(Corinna Knapp)
May 19, 2022, 12:34pm
14
I just used your code .
And after I hit save:
May I asked is there a possibility to outsource my json code? So I only have one json code for 3 forms.
Margo
(Margo)
May 20, 2022, 5:57am
15
@Sternchen ,
Please share the full code you used when testing the form and got these errors.
Not sure I understood you. Do you want to store the code in a file and re-use it on multiple forms? If so, please see this post .
Sternchen
(Corinna Knapp)
May 20, 2022, 6:10am
16
I just used the code you have sent me.
Margo
(Margo)
May 20, 2022, 10:17am
17
@Sternchen ,
Please export the form with the List or Library control and the code you've been testing and send it to me. I'll check it on my side.
Sternchen
(Corinna Knapp)
May 20, 2022, 10:33am
18
test_form.xfds (36.0 KB)
Here is my form with your code.
Thank you
Sternchen
(Corinna Knapp)
May 23, 2022, 6:47am
19
I really don´t know why it is working now but this code works for me:
fd.validators.push({
name: 'MyCustomValidator',
error: 'Upload files',
validate: function(value) {
if (fd.control('SPDataTable1').widget.dataItems().length < 1){
return false;
}
return true;
}
});
It was your first code and now it seems working.
Thank you @Margo
Now I want to make it require only when the IBAN field has a value.
I tried it like this:
if(fd.field('IBAN').value != ''){
fd.validators.push({
name: 'MyCustomValidator',
error: 'Please upload a IBAN file',
validate: function(value) {
if (fd.control('SPDataTable1').widget.dataItems().length < 1){
return false;
}
return true;
}
});
else{
}
But this isn´t working. Hope you can help me.
Margo
(Margo)
May 23, 2022, 8:04am
20
@Sternchen ,
I'm glad the validation is working.
You need to add a condition inside the validator instead, like this:
fd.validators.push({
name: 'MyCustomValidator',
error: 'Upload files',
validate: function(value) {
if (fd.control('SPDataTable1').widget.dataItems().length < 1 && fd.field('IBAN').value){
return false;
}
return true;
}
});
Sternchen
(Corinna Knapp)
May 23, 2022, 8:18am
21
Thank you
This solved my problem. Just so simple.
1 Like