Due to the different view modal with gravityform (new vs edit entry), I decided to manage it by SQL request and the tab editing. However, my fields need some validation rules. For example:
I have 2 date fields (date1 and date2) that have to follow this rule before saving in database:
Both date must be in the current month
date1 must be <= than date 2
If the rule is not valid then an error must be displayed to the user.
The other question is for the show/hide columns. By using SQL request and editing functionality I have to get my ID column. However I don't want to this this column in the front-end. Even if I hide it in the tab, the user still have the choice to add it through the column visibility dropdown. (cf.attachment).
What you're asking is custom work, so we can only provide advice. Great work on finding the hooks!
As you probably saw in the other ticket, formData is forwarded - which contains the tableId of the current table and the data user entered through the modal (which is an array in column_name -> column value format).
We don't have the data about columns, but you can use loadColumnsFromDB function, like in the example:
function updateValuesBeforeSave($formData,$tableID){ //Helper method that load columns config data from DB
$columnsData = \WDTConfigController::loadColumnsFromDB($tableID);
foreach ($columnsData as $column){
if ($column->orig_header == 'name_of_the_orig_header_for_your_column') {
$formData[$column->orig_header] = 1;//we set 1 but you will replace here what ever you need
}
} return $formData;
}
add_filter('wpdatatables_filter_formdata_before_save','updateValuesBeforeSave', 2, 10);
I'm not sure about other hooks, but if this doesn't help, please let me know, and I'll reach out to one of our developers.
Again, please note that this is custom work, which is not covered in the provided support for the plugin, so I can't guarantee that we'll be able to help.
The hook allows me to get the data and to do my logic in order to valid or not the data. However, the hook must return the $formData otherwise the tab is frozen.
EDIT:
I added into the wdtSaveTableFrontend function (which handles the edit ajax request) a new filter just before the db connection and save, in order to return $returnResult with error message. Then if the $returnResult has something in 'error' I skip all the database (connection and update) part. I got the error message and the value is not updated as expect.
However I'm stuck because now in your ajax request, if the ajax is a success but the $returnResult var has in its error value something the script block the tab with an infinity loader... which is removed only is the value of this error is empty.
My question is now: Could you add a filter to make back-end validation of our fields (I did it with 3 lines of code)? And could you also handle the front-end error message without blocking all the tab?
If needed I can push the feature on your code versioning solution. Adding validation rules to datatables edditing is mandatory to me and this is the last part of my website.
I test the data seized by the user regarding some logic. For example, I have 2 date field (date1 and date2) following those rules:
- date1 and date2 must be in current months
- date2 must be earlier or equal then date1.
If both condition are not validated, I want to display a custom error message to the user and not update ma db.
Take note that what I did can be do in better way :
In your wdt_ajax_actions.php I added into the "wdtSaveTableFrontend" function a new filter "wpdatatables_filter_formdata_validation_before_save" that must return the $returnResult var. Then I test if this var has no error message to follow the db connection and update. Here the code:
$formData = apply_filters('wpdatatables_filter_formdata_before_save', $formData, $tableId);
$returnResult=apply_filters('wpdatatables_filter_formdata_validation_before_save', $formData, $tableId, $returnResult,$idVal);
if(is_empty($returnResult['error'])) {
// If the plugin is using WP DB
if (!(Connection::isSeparate($tableData->connection))){...}else{...}
}
Then in the wdt.frontend.js I added into the function doing the ajax request the following code to disable the infinite loader in case of success request with something in the error message:
One of our developers took a look at this, and said he created a task.
So, we'll see if there's anything we can do about this, maybe add a hook, or add some changes to our code. We'll be working on it for the next update, although I cannot say if we'll have the time to include it in the next update.
Dear support,
I have 2 questions:
Due to the different view modal with gravityform (new vs edit entry), I decided to manage it by SQL request and the tab editing. However, my fields need some validation rules. For example:
I have 2 date fields (date1 and date2) that have to follow this rule before saving in database:
If the rule is not valid then an error must be displayed to the user.
The other question is for the show/hide columns. By using SQL request and editing functionality I have to get my ID column. However I don't want to this this column in the front-end. Even if I hide it in the tab, the user still have the choice to add it through the column visibility dropdown. (cf.attachment).
Thanks in advanced.
I found in other tickets and documentation about the hook:
But it's seem to be called after the data has been updated in database :(
I also found in some tickets the filter:
That seem to match to my needs but I'm not able to stop the update and display an error message.
Do you have have another hook/filter or solution that could match my needs?
Best,
Hello Fabien
What you're asking is custom work, so we can only provide advice. Great work on finding the hooks!
As you probably saw in the other ticket, formData is forwarded - which contains the tableId of the current table and the data user entered through the modal (which is an array in column_name -> column value format).
We don't have the data about columns, but you can use loadColumnsFromDB function, like in the example:
I'm not sure about other hooks, but if this doesn't help, please let me know, and I'll reach out to one of our developers.
Again, please note that this is custom work, which is not covered in the provided support for the plugin, so I can't guarantee that we'll be able to help.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hello Aleksandar,
Thanks for the answer.
The hook allows me to get the data and to do my logic in order to valid or not the data. However, the hook must return the $formData otherwise the tab is frozen.
EDIT:
I added into the wdtSaveTableFrontend function (which handles the edit ajax request) a new filter just before the db connection and save, in order to return $returnResult with error message. Then if the $returnResult has something in 'error' I skip all the database (connection and update) part. I got the error message and the value is not updated as expect.
However I'm stuck because now in your ajax request, if the ajax is a success but the $returnResult var has in its error value something the script block the tab with an infinity loader... which is removed only is the value of this error is empty.
My question is now: Could you add a filter to make back-end validation of our fields (I did it with 3 lines of code)? And could you also handle the front-end error message without blocking all the tab?
Thanks
Hi,
If needed I can push the feature on your code versioning solution. Adding validation rules to datatables edditing is mandatory to me and this is the last part of my website.
Best,
Hi again Fabien
Please share the code with me, so I can forward it to one of our developers for review. What exactly are you validating?
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hello Aleksandar,
I test the data seized by the user regarding some logic. For example, I have 2 date field (date1 and date2) following those rules:
- date1 and date2 must be in current months
- date2 must be earlier or equal then date1.
If both condition are not validated, I want to display a custom error message to the user and not update ma db.
Take note that what I did can be do in better way :
In your wdt_ajax_actions.php I added into the "wdtSaveTableFrontend" function a new filter "wpdatatables_filter_formdata_validation_before_save" that must return the $returnResult var. Then I test if this var has no error message to follow the db connection and update. Here the code:
Then in the wdt.frontend.js I added into the function doing the ajax request the following code to disable the infinite loader in case of success request with something in the error message:
It's works for me but code skills are needed.
I think it will be better to manage it on the column setting with a proper validation panel like you did with the conditional appearance column tab.
Best,
Thanks Fabien
One of our developers took a look at this, and said he created a task.
So, we'll see if there's anything we can do about this, maybe add a hook, or add some changes to our code. We'll be working on it for the next update, although I cannot say if we'll have the time to include it in the next update.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables