Unable to add multiple attribute into cssClass property

Hi expert,

I would like to know if I can add more than one attribute into cssClass like below.

Generally only 1 cssClass ==> cssClass={"e-small"} OR cssClass={"e-error"} works but I want to add both logic for displaying error (e-error or undefined AND e-small)



For below -- I use cssClass={e-small} but I need to include e-error. So that it will display red rectangle when submit because it requires a mandatory field.


Example like what I like: --> it works but I need to include e-small. Notice the difference height.

12 Replies

DL Deepa Loganathan Syncfusion Team October 23, 2018 04:43 PM UTC

Hi DeBao Chua,  
 
Thank you for contacting Syncfusion support.  
 
As of now, the Datepicker component does not support adding multiple classes and we have considered this as a bug and logged a bug report at our end. The fix for this issue is estimated to be available in the upcoming service pack release.  
 
However, you could add additional classes to the Datepicker using addClass method from ej2-base library and for your convenience, we have prepared a sample using the same. Please check. 
 
 
Here, the classes e-success and e-form-success will be added to the wrapper element of the DatePicker if form validation succeeds else e-error class will be added. 
 
Please let us know if you have any further queries. 
 
Regards,  
 
Deepa L. 



DC DeBao Chua October 24, 2018 07:32 AM UTC

Hi Deepa,

Thanks for your explanation and source codes.

Now I know it is one of bug and I hope you could implement more than one attribute into cssClass property and then it will be a clean/simple code.

The source codes you provide me is quite longer but it is possible. However when I tried to click the datetimepicker component and tried to leave which is called "props.meta.touched" and it does not display red rectangle (error). Is there a workaround to include props.meta.touched?

As I understand clicking "submit button" works perfectly. I am trying to think of better and simple solution to include props.meta.touched and props.meta.error which comes from Field component - final form react. I use Field and DatePickerComponent together. The code I use below is something like that:

                <Col xl={4}>
<Field name={fields.VertragStartDatum.listDataField} validate={required} required={true}>
{(props: any) => <DatePickerField placeholder={`${fields.VertragStartDatum.label} *`} {...props} />}
</Field>
</Col>




DC DeBao Chua October 24, 2018 08:36 AM UTC

Hi Deepa,

I come up with a brillant idea after observing your source codes because I am thinking of adding the classList (either e-error OR undefined) based on checking if this div class contains undefined when the value is empty, it will add "e-error" otherwise add undefined.

However I encounter a problem due to DatePickerComponent Property. I am not sure how to deal with this.

Sample Code I come up with an idea:

export const dateRequired = (dateContainer: DatePickerComponent, value: string, allValues:object) => {
if (!value) {
if (dateContainer.inputWrapper.container.classList.contains(undefined))
{
removeClass([dateContainer.inputWrapper.container], [undefined]);
}
// createValidationMessage(Severity.Error, "Dies ist ein Pflichtfeld!").message;
// addClass([dateContainer.inputWrapper.container], ["e-error"]);
dateContainer.inputWrapper.container.classList.add("e-error");
}

else {
if (dateContainer.inputWrapper.container.classList.contains("e-error"))
{
removeClass([dateContainer.inputWrapper.container], ["e-error"]);
}
dateContainer.inputWrapper.container.classList.add(undefined);
}

// dateContainer.inputWrapper.container.classList.add("e-error");
// return value ? undefined : createValidationMessage(Severity.Error, "Dies ist ein Pflichtfeld!").message;
}


Error: What am I missing?
Failed to compile.
(30,27): Property 'inputWrapper' is protected and only accessible within class 'DatePicker' and its subclasses.


My question is I am wondering how I can check if the div class contains undefined OR "e-error"

this class contains "undefined" but I am wondering how to check if it contains then true otherwise false --> is there a code? Something like
if (dateContainer.inputWrapper.container.classList.contains("undefined")) {
     true
}

else { false }

As you see the blue highlighted row below, I am wondering how i can append to this div class like putting id so that I will use document.getElementByID("hello").classList.add(undefined); But I am not sure where I can add id into this div class because it belongs to DropdownList Component?


this class contains "e-error" but I am wondering how to check if it contains then true otherwise false --> is there a code? Something like
if (dateContainer.inputWrapper.container.classList.contains("e-error")) {
     true
}

else { false }

As you see the blue highlighted row below, I am wondering how i can append to this div class like putting id so that I will use document.getElementByID("hello").classList.add("e-error"); But I am not sure where I can add id into this div class because it belongs to DropdownList Component?


Lastly, I am baffled how I can check if this class contains undefined or not. I am thinking like id=picker so that it can check but I am not sure how it works like contains etc.

<DatePickerComponent
id="datepicker"


DL Deepa Loganathan Syncfusion Team October 25, 2018 12:52 PM UTC

Hi DeBao, 
 
Sorry for the inconvenience caused. 
 
We were able to reproduce the reported issue and is because of the accessibility level of the wrapper element in our component.  
 
Instead, you could access the input wrapper and add classes to the element by navigating through the Datepicker element as given in the below code. 
 
(this.dateContainer.element.parentElement as HTMLElement).classList.contains('e-success') 
 
 
We understood that you would like to validate the input upon focusout event of input and this could be achieved by using the blur event of Datepicker. We have prepared a sample based on your requirement that can be downloaded from the below link. 
 
 
 
Please, let us know if you need any further assistance. 
 
Regards, 
Deepa L. 



DC DeBao Chua October 25, 2018 01:29 PM UTC

Hi Deepa,

Thanks for the explaination and source codes.

I have checked it and it is working. It is what I am looking for but I have not tested it on my side. Anyway I look forward to new pack release that includes cssClass property that supports more than one attribute and it will be easier like e.g. cssClass={`e-small ${this.props.meta.touched && this.props.meta.error ? "e-error" : "e-success"}`}


DL Deepa Loganathan Syncfusion Team October 26, 2018 09:50 AM UTC

Hi DeBao,  
 
You are welcome. We will update you once the service pack tentatively scheduled for release by next week is released and available for download.  
 
We appreciate your patience until then.  
 
Regards,  
Deepa L. 



DC DeBao Chua October 31, 2018 03:45 PM UTC

Hi Deepa,

I saw the latest version of Syncfusion --> https://ej2.syncfusion.com/react/documentation/release-notes/16.3.29#chart

DatePicker

BUG FIXES
  • Added multiple class name support for the cssClass property.
I already upgrade to new version 16.3.29 and added another class name into cssClass and it works perfect. Thank you for fixing it.

I am waiting for your next version to work on Dropdownlist - support multiple class name for cssClass property. Keep me update. Thanks.


DL Deepa Loganathan Syncfusion Team November 1, 2018 12:58 PM UTC

Hi DeBao,   
 
 
Thanks for the update.  
 
 
We would let you know that Dropdownlist already has support for adding multiple cssClass attribute. So, as promised, we will provide support for react final forms to use the validation classes for our controls which will be included in our Volume 4, 2018 release. We appreciate your patience until then. 
 
 
Please, let us know if you need any further assistance.  


Regards, 
  
Deepa L. 



DC DeBao Chua November 12, 2018 11:31 AM UTC

Hi expert,

Could you please include more than one attribute into cssClass property for CheckBox Component? Thanks. So I am waiting for new version of Syncfusion React that works with CheckBox and DropdownList. Thank you very much.

cssClass={this.state.valueString !== "Individual" ? "e-small" : "e-disabled"} --> It works

// cssClass={this.state.valueString !== "Individual" ? "e-small" : "e-disabled e-small"} --> It is not working

Another bug for disabled property (if else statement) to toggle either false or true below:

// disabled={true} // the hardcode is working
// disabled={false} // the hardcode is working
// disabled={this.state.checkboxEditable}} // initial state as false ==> It is working but when I select dropdownlist, it does not trigger

// for example
// this method is for Dropdownlist --> it is not triggering itself --> I think it is a bug you need to investigate
private handleValueChange = (value: string) => {
     if (value === "Individual") {
          this.setState({this.state.checkboxEditable: true});
}

     else {
          this.setState({this.state.checkboxEditable: false});
     }
}



Regards,
De Bao


DL Deepa Loganathan Syncfusion Team November 13, 2018 06:19 PM UTC

Hi DeBao 
 
Thanks for contacting Syncfusion support. 
  
Query #1: multiple classes support in Checkbox and Dropdownlist 
  
We would like let you know that CheckBox and Dropdownlist controls already has support for adding multiple cssClass attributes. Please find the code example for adding multiple classes in Checkbox and Dropdownlist.  
JS:  
 
<div className='row'> 
                    <CheckBoxComponent checked={true} label='CheckBox: true' ref={(scope) => { this.checkboxObj = scope; }} cssClass={this.state.valueString !== "Individual" ? "e-small" : "e-disbled e-small"}></CheckBoxComponent> 
 
 
<DropDownListComponent id="games" dataSource={this.sportsData}  cssClass={this.state1.valueString !== "Individual" ? "e-small" : "e-disable e-small"} ref={(dropdownlist) => { this.listObj = dropdownlist; }}  change={this.onChange_alert.bind(this)} fields={this.fields1}  placeholder="Select a game" value={this.value1} popupHeight="220px" /> 
 
 
 We have prepared a sample for your reference to showcase the usage of multiple css classes in Dropdownlist and checkbox. Please check the below link. 
  
 
Query #2: Dropdownlist change event not working 
 
We have checked with a sample to check the change event of Dropdownlist and we can confirm that it is working as expected. We have showcased the change event in above Stackblitz sample.  
 
After cross checking with the above sample. if you are facing any difficulties in using Checkbox or dropdownlist, please get back to us with an issue replicated sample or the component definition file that would help us in replicating the reported issue. The details you provide will help us assist you better. 
 
Query #2: Disable state binding in checkbox is not working 
  
We were able to reproduce the reported issue and we need to validate more on this. So, we will validate further and update you with further details on November 15th, 2018. Meanwhile we would suggest you the work around solution to add the disabled property for checkbox component by using the scope reference variable. Please find the sample link below.  
  
JS:  
 <div className='row'> 
                    <CheckBoxComponent checked={true} label='CheckBox: true' ref={(scope) => { this.checkboxObj = scope; }} cssClass={this.state.valueString !== "Individual" ? "e-small" : "e-disbled e-small"}></CheckBoxComponent> 
                </div> 
onChange(args) { 
     this.checkboxObj.disabled = (args.itemData.Value == "TRUE") ? true : false; 
    } 
  
Kindly check the above sample link and get back to us if you need any further assistance on this. 
 
Regards,  
Deepa L. 



DC DeBao Chua November 14, 2018 11:00 AM UTC

Hi Deepa,

Thanks for your feedback, explaination and source codes.

Back to your questions below:

Query #1: multiple classes support in Checkbox and Dropdownlist 
  
We would like let you know that CheckBox and Dropdownlist controls already has support for adding multiple cssClass attributes. Please find the code example for adding multiple classes in Checkbox and Dropdownlist.  --> For my case: It does not work on my side. I am using Typescript. See the error code below:

Error:


Code:






Error:
It occurs when I tried to select "Individuell" but it does not occur when I select the rest of values except Individuell.

Query #2: Dropdownlist change event not working 
 
We have checked with a sample to check the change event of Dropdownlist and we can confirm that it is working as expected. We have showcased the change event in above Stackblitz sample.  --> For my case: It does not work although I use ref. I use TypeScript.

I am using CheckBoxField that will link to CheckBoxComponent but ref does not work. 

Code:
CheckBoxField


CheckBoxComponent




Error:


I am still baffled with CheckBoxComponent especially ref.. I am using "@syncfusion/ej2-buttons": "^16.3.30" so I must update new version.

As for Dropdownlist --> Thanks for fixing this bug --> I see you use
"@syncfusion/ej2-buttons": "^16.3.30",
"@syncfusion/ej2-react-dropdowns": "16.3.32",


https://ej2.syncfusion.com/react/documentation/release-notes/ --> I do not see the latest version of React Syncfusion e.g. 16.3.32?? Is there a new version for React TypeScript?

Query #3: Disable state binding in checkbox is not working 
  
We were able to reproduce the reported issue and we need to validate more on this. So, we will validate further and update you with further details on November 15th, 2018. Meanwhile we would suggest you the work around solution to add the disabled property for checkbox component by using the scope reference variable.
--> I tried to add the scope reference variable but it does not work. I hope you can get disabled property working like e.g. disabled={this.state.valueString === "Individual" ? false : true } ==> I would prefer it as it is a clean and simple code but do get back to me once you have the update with further details. :-)


DL Deepa Loganathan Syncfusion Team November 15, 2018 09:32 AM UTC

Hi DeBao  
 
Sorry for the inconvenience.  
 
We have validated the reported issues and have updated our responses to your queries based on the analysis in an incident under your Direct Trac account. Please follow up the incident for more details.  
  
Please click here to login to your Direct Trac login with the below link.  
  
  
Regards,  
Deepa L. 
 


Loader.
Up arrow icon