vendredi 23 octobre 2020

Problem with set initialValues for checkboxes in react-hook-form

here is my example: https://codesandbox.io/s/frosty-bush-pmc5f?file=/src/CheckboxDisplay.js

I have problem, because i want set initialParameters members.fields to checkboxes that these tags will choosed at the beginning and will display in our input.

For the moment it work, that we can choose tags and save what we choosed.

I want display tags which are in object members in data.js file

Anyone know answer to this question?




VBA Checkbox: Remove mark when information is missing

In the file I'm working on, I have set a checkbox that needs to be ticked to confirm that your boss has read the report. If information is missing, you will get a warning message telling you to fill all the data. Now I noticed that if you tick the checkbox after filling the whole template and then you delete some information, the ckeckmark does not disappear. Is there a way to make the checkmark go away if you delete some data afterwards, followed by a message to fill the whole info again and also tick the checkbox again?

This is the code I'm using:

Private Sub CheckBox1_Click()

Dim c As Range

For Each c In

ActiveSheet.Range(("D12:E20,C22:E22,D26:D27,F26,D30:D33,D35:D36,E31,D39,D40:E42,D45:D46,D49,D52,D53:F58,D61,C64:F65,C67:F67,D68,C71:F72,C74:F74,D75,C78:F79,C81:F81,D85"))

If c = "" Then

MsgBox "Please fill-out the missing cells!"

Cancel = True

If CheckBox1.Value = True Then CheckBox1.Value = False

Exit For

End If

Next

End Sub

Thank you!




jeudi 22 octobre 2020

How to capture whether a checkbox has been checked or not?

I have a Bootstrap form modal being used for a webinar signup. I've removed the other fields, but I have multiple text fields that are being captured and pushed to a CMS.

It's just these 3 checkboxes that I can't seem to get to push data across correctly. The checkboxes are recording all as "on" if the form is submitted once, but if the form is submitted a second time then the checkboxes that are checked/not checked will push through "on" and "off" accordingly. So it works on the second submit, but not on the first. Any help would be greatly appreciated. I'm new to javascript and jquery, so i'm now at the point of guessing.

$(document).ready(function() {
  $('.register-webinar').click(function() {
    checked = $("input[type=checkbox]:checked").length;

    if (!checked) {
      alert("You must select at least one session.");
      return false;
    }
  });

  $('input.webinar').change(function() {
    if ($(this).is(":checked")) {
      $(this).val("on")
    } else {
      $(this).val("off")
    }
  });

  $('#railway_form').on("submit", function(e) {
    e.preventDefault();
    setTimeout(AoProcessForm(this), 200);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">

<div class="form-popup-bg">
  <div class="form-container">
    <button id="btnCloseForm" class="close-button">X</button>
    <h1 style="text-align:center;">Register your attendance</h1>
    <p style="text-align:center;">Please select which session/s you wish to attend.</p>
    <form name="railway_webinar" id="railway_form" class="railway_webinar" action="">
      <div class="form-group">
        <input type="checkbox" id="Webinar_1" name="Webinar_1" class="webinar">
        <label for="Webinar_1">webinar 1</label><br/>
        <input type="checkbox" id="Webinar_2" name="Webinar_2" class="webinar">
        <label for="Webinar_2">webinar 2</label><br/>
        <input type="checkbox" id="Webinar_3" name="Webinar_3" class="webinar">
        <label for="Webinar_3">webinar 3</label>
      </div>
      <input type="submit" value="Reserve my seat!" class="form-block-cta register-webinar" />
    </form>
  </div>
</div>



How can I dispatch a checkbox click programmatically?

I've tried several javascript functions here and there but it seems that none of them worked for me. What I'm doing is displaying a tower, that has as much stages as the user wish. This is basically creating html tags using Js for every stages and the last one is a checkbox. The thing I'd like to do is that when I click on a checkbox, all the other ones that are over this one would check programmatically also. So this is what I did:

    let event = new Event('click');

    //Here, q is the maximum stage that the user set.

    document.addEventListener('click', function(e) {
        let readStr = e.target.id;
        if (readStr.startsWith("checkboxFan") && e.isTrusted) {
            for (let r=parseFloat(readStr.substr(-1))+1; r<=q; r++) {
                document.getElementById("checkboxFan"+r).dispatchEvent(event);
            }
        }
    }, false);

And it's finding the IDs well and doing what I want, but the dispatchEvent isn't working as expected. In fact, it's not working at all. Also, the "click()" function works but the isTrusted is triggered, which is not what I want because the checkbox has to be clicked by the user.

Any solutions ?

Many thanks, have a nice day !




mercredi 21 octobre 2020

Change dropdown to multi-select checkbox in asp.net

I'm completely new to asp and I have a from in which the user has to select so many features from a dropdown list one in a time. It's frustrating and takes a lot of time. Now I'm thinking of changing this dropdown to a multi-select checkbox. This way user can choose all the features at once.

Here's my code:

    <div class="form-group row">
        <label class="control-label col-md-2" for="Title">Features</label>
        <div class="col-md-12 row">

            @Html.DropDownList("FeatureID", (SelectList)ViewBag.FeatureID, "-- Select ---", new { id = "FeatureID", @class = "form-control col-md-7" })

            <div class="col-md-5"  style="display: none">
                <input class="form-control" type="text" placeholder="Enter Feature Value" id="txtvalue"/>
                @*<textarea class="form-control" rows="5" type="text" placeholder="Enter Feature Value" id="txtvalue"></textarea>*@
            </div>
            <div class="col-md-2">
                <a class="btn btn-success " onclick="addFeature()">
                    <i class="zmdi zmdi-plus"></i>
                </a>
            </div>
        </div>
    </div>
    <div id="showfeaturelist">
        @Html.Action("ShowFeature")
    </div>

Any help would be much appreciated!




How can i remember the previsiously selected item of a QlistWidget

Is there another way to remember previously selected items of a QlistWidget without making lists? in the example below I tried to do it, only I can't check the items while reading the dictionary list. here is my sample code:

from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import (QWidget, QListWidget, QVBoxLayout, QApplication) from datetime import date, timedelta

class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(532, 292) self.lists={} self.itm=0 self.pushButton_ok = QtWidgets.QPushButton(Dialog) self.pushButton_ok.setGeometry(QtCore.QRect(336, 251, 88, 34)) self.pushButton_ok.setObjectName("pushButton_ok") self.pushButton_anulla = QtWidgets.QPushButton(Dialog) self.pushButton_anulla.setGeometry(QtCore.QRect(426, 251, 88, 34)) self.pushButton_anulla.setObjectName("pushButton_anulla") self.widget = QtWidgets.QWidget(Dialog) self.widget.setGeometry(QtCore.QRect(5, 13, 520, 221)) self.widget.setObjectName("widget") self.gridLayout = QtWidgets.QGridLayout(self.widget) self.gridLayout.setContentsMargins(10, 10, 10, 10) self.gridLayout.setObjectName("gridLayout") self.listWidgetdate = QtWidgets.QListWidget(self.widget) self.listWidgetdate.setObjectName("listWidgetdate") self.gridLayout.addWidget(self.listWidgetdate, 0, 1, 1, 1) self.listWidgetlav = QtWidgets.QListWidget(self.widget) self.listWidgetlav.setObjectName("listWidgetlav") item = QtWidgets.QListWidgetItem() self.listWidgetlav.addItem(item) self.gridLayout.addWidget(self.listWidgetlav, 0, 0, 1, 1)

    self.listWidgetlav.currentItemChanged.connect(self.itemActivated_event)
    self.list1=["B","C","D"]
    for i in range(len(self.list1)):
        item = QtWidgets.QListWidgetItem()
        self.listWidgetlav.addItem(item)
        item.setText(self.list1[i])
    self.listWidgetlav.setCurrentRow(0)
     

    self.retranslateUi(Dialog)
    QtCore.QMetaObject.connectSlotsByName(Dialog)

def retranslateUi(self, Dialog):
    _translate = QtCore.QCoreApplication.translate
    Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
    self.pushButton_ok.setText(_translate("Dialog", "Ok"))
    self.pushButton_anulla.setText(_translate("Dialog", "Anulla"))
    __sortingEnabled = self.listWidgetdate.isSortingEnabled()
    self.listWidgetdate.setSortingEnabled(False)
    self.listWidgetdate.setSortingEnabled(__sortingEnabled)
    __sortingEnabled = self.listWidgetlav.isSortingEnabled()
    self.listWidgetlav.setSortingEnabled(False)
    item = self.listWidgetlav.item(0)
    item.setText(_translate("Dialog", "A"))
    self.listWidgetlav.setSortingEnabled(__sortingEnabled)

     

def load_item(self): 
    self.list2=self.dates(date(2019,5,3),date(2019,5,6))
    self.listWidgetdate.clear()
    for i in range(0,self.listWidgetdate.count()):
        self.listWidgetdate.takeItem(i)
    for i in range(len(self.list2)):
        item1 = QtWidgets.QListWidgetItem()
        self.listWidgetdate.addItem(item1)
        item1.setText(self.list2[i])
        item1.setFlags(QtCore.Qt.ItemIsUserCheckable|QtCore.Qt.ItemIsEnabled)
        item1.setCheckState(QtCore.Qt.Unchecked)
             

def itemActivated_event(self):
    self.make_settigs(self.listWidgetlav.currentRow())
    self.load_item()
    print(self.listWidgetlav.currentRow())

def on_clicked(self):
    self.list_of_imp=[]
    for row in range(0, self.listWidgetdate.count()):
        it = self.listWidgetdate.item(row)
        if it.checkState() == QtCore.Qt.Checked:
            # print(it.text())
            self.list_of_imp.append(True)
        else:self.list_of_imp.append(False)
    return self.list_of_imp

def dates(self,datein,dateout):
    self.list_dates=[]
    # start_date = datein
    # end_date = dateout

    st_date = datein
    ed_date = dateout

    delta = ed_date - st_date

    for i in range(delta.days+1):
        day =st_date + timedelta(days=i)
        e=str(day)
        self.list_dates.append(e)

    return self.list_dates

def make_settigs(self,ind):
    self.tmp=self.on_clicked()
    self.lists['lst'+str(self.itm)]=self.tmp
    self.current=ind
    checked=2
    unchecked=0
-----   The problem is here ------
    try:
        if len(self.lists['lst'+str(self.current)])!=0:
            for i in range(len(self.lists['lst'+str(self.current)])):
                it = self.listWidgetdate.item(i)
                if (self.lists['lst'+str(self.current)][i])==True:
                    if it.checkState() == QtCore.Qt.Unchecked:
                        print(it.checkState, "------checked--------")
                        it.setCheckState(checked)
                    else:
                        it.setCheckState(checked)
                elif (self.lists['lst'+str(self.current)][i])==False:
                    if it.checkState() == QtCore.Qt.Checked:
                        print(it.checkState, "-----unchecked---------")
                        it.setCheckState(unchecked)
                    else:
                        it.setCheckState(unchecked)

    except: print("We don t have the list yet")

    self.lists['lst'+str(self.itm)]=self.tmp
    self.itm=ind


    print(self.lists)

    

if name == "main": import sys app = QtWidgets.QApplication(sys.argv) Dialog = QtWidgets.QWidget() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() sys.exit(app.exec_())




mardi 20 octobre 2020

Creating Custom MUI Checkbox Component to work with FormControlLabel

I have created a custom checkbox component that wraps a Material UI checkbox.

export default function PublishCheckbox({record}) {
const {publishData} = record;
const {categoryNameForId} = useStoreState(state => (state.document))
const togglePublishDocument = useStoreActions(actions => actions.document.togglePublishDocument);

const handleClick = (event) => {
    event.stopPropagation();
    togglePublishDocument({publishData});
}

return (
    <Checkbox disabled={source === 'PP'} checked={published} color="primary"
              onClick={handleClick} size="medium"/>
)
};

PublishCheckbox.propTypes = {
    record: PropTypes.object.isRequired,
}

It works fine for most of my cases, except where I try use a FormControlLabel component with it.

<FormControlLabel className={classes.publishButton} label="Publish" control={<PublishCheckbox record={file}/>}/>

What happens is that clicking the checkbox calls the onClick action of my custom component twice. Clicking on just the label calls it just once as you would expect. I think this is because the FormConrolLabel is specifically designed to work with MUI checkboxes (and radios and switches), but my custom component is not exposing and using the props and refs the same way so some of that Material UI magic is getting lost.

How can I change my custom checkbox to work with FormControlLabel and stop calling my onClick event twice?