Hi,

In Foex Grid, one column is containing checkboxes. I want to validate like one and only one checkbox should be selected from all the rows of grid. see image:

alt text

In this image, checkbox from first row is selected, if user tries to check any other checkbox, system should give some error. and if user doesn't check any of the checkbox from any row, again system should give some error message.

Please suggest, how can I validate it in this way?

Thanks

Mudi

asked 25 Jul, 06:17

Mudi's gravatar image

Mudi
1825
accept rate: 7%


Hello,

If front-end validation of the currently loaded records is enough, you could do it like this:

Create a dynamic action for your grid, set the triggering element to be your grid region and event FOEX Grid - after render. The true action - APEX / Execute Javascript, uncheck the 'fire on load' option. Add this javascript code:

var grid = this.data.widget;
grid._getColumn('CB').on('beforecheckchange', function(column, rowIndex, checked) {
   var prevent = false,
       checkedCount = 0;
   grid.getStore().each(function(record) {
      if (record.get('CB') === true) {
         checkedCount++;
         if (checked && checkedCount > 0) {
            Ext.Msg.alert('Oops', 'You can select only one record.');
            prevent = true;
            return false;
         }
      }
   });
   return !prevent;
});

Where CB is the checkbox column name. Hope this helps.

For the other case (1 record must be selected), the idea is similar: get the grid and go through the records:

var grid = Ext.getCmp('grid'), //I am using the static ID of the grid 
    passed = false;

grid.getStore().each(function(record) {
  if (record.get('CB') === true) {
     passed = true;
     return false;
  }
});
if(!passed) {
  Ext.Msg.alert('Oops', 'You must select one record.');
}
link

answered 26 Jul, 05:42

FOEX-SUPPORT's gravatar image

FOEX-SUPPORT
4.7k15
accept rate: 32%

edited 26 Jul, 09:26

Dear support team,

Thank you so much, for your kind support as always!

It is working very fine to restrict the user to select only one at a time. But one thing is still pending, user should select at least one checkbox also. how can I ensure this while clicking the save button.

Please help!

Thanks

Mudi

(26 Jul, 07:07) Mudi Mudi's gravatar image

See the edited answer.

(26 Jul, 09:26) FOEX-SUPPORT FOEX-SUPPORT's gravatar image

Perfect!

Thank you so much, you really made my life easier :D

one last thing please, when I click the save button without selecting one record, it is giving me popup message, to 'must select 1 record', but it is also saving the data. It should stop the commit action also.

Please help!

Thank you once again for your kind help.

Mudi

(27 Jul, 00:10) Mudi Mudi's gravatar image

You could use the same code as in the last code block (which verifies at least 1 record checked), but in the last condition you should add a line inside of the curly braces:

if(!passed) {

this.data.fxEvent.stopProcessing = true; //add this

...

}

Then just create some appropriate DA for it with an event FOEX Grid - Before Save or FOEX Grid - Before CRUD depending on which works better for you.

(27 Jul, 10:42) FOEX-SUPPORT FOEX-SUPPORT's gravatar image

It worked for me.

Thank you :)

Mudi

(30 Jul, 02:43) Mudi Mudi's gravatar image

I'm back once again, during the testing today I found a problem regarding this solution as, when I try to delete the very last row in the grid, it doesn't allow me to delete, firing the DA on FOEX Grid-Before CRUD, and giving me the message as to select 1 checkbox.

The javascript code is as:

var grid = Ext.getCmp('grid'), //I am using the static ID of the grid passed = false;

grid.getStore().each(function(record) { if (record.get('CB') === true) { passed = true; return false; } }); if(!passed) { Ext.Msg.alert('Oops', 'You must select one record.'); }

May be we need to put an extra condition like, if grid is having anymore records, don't go for this validation check?

Please help!

Mudi

link

answered 17 Aug, 06:14

Mudi's gravatar image

Mudi
1825
accept rate: 7%

You could wrap the grid.getStore().each(.....) in an if condition: if(grid.getStore().count() > 1) { .... }

(17 Aug, 10:52) FOEX-SUPPORT FOEX-SUPPORT's gravatar image

Thank you!

(20 Aug, 03:46) Mudi Mudi's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×552
×41
×36

Asked: 25 Jul, 06:17

Seen: 197 times

Last updated: 20 Aug, 03:46

FOEX Links