jeudi 31 août 2023

How to make checkbox in pytelegrammbot, using a data from list

I'm working on a telegramm bot, and during one process, I get a JSON data consisting of several items with 2 fields, and I need to make so, that after pressing button, data converts in checkbox and user can choose, which item do they have, and then I need to process those chosen items to server via POST, but I'm stuck on converting data and showing it to the user. Data is stored in form of list, consisting of dictionary with fields "Name" and "ID"

I've tried this code, but it's 100% incorrect (since it not working), and I'm currently lacking knowledge on this matter, and having trouble with documentation. All this goes after pressing a button, sure that all correct and working before this part

res = requests.get(url=URL3, auth=auth, params={'login': user_login})
data = json.loads(res.content)
results = []  
for item in data["Description"]:
    result = {}
    for key in ["Asset", "InventoryNumber"]:
        result[key] = item[key]
        results.append(result)  
markup = types.InlineKeyboardMarkup(row_width=len(results))
for i, result in enumerate(results):
    checkbox = types.InlineKeyboardButton(f"Name: {result['Asset']}\nID: {result['InventoryNumber']}",
                                          callback_data=f"choice_{i}")
    markup.add(checkbox)
msg = bot.send_message(call.message.chat.id, text='Choose needed assets', reply_markup=markup)
threading.Thread(target=func_del_mess, args=(msg.chat.id, msg.message_id,)).start()




mercredi 30 août 2023

How to modify the following shiny code to obtain row indexes selected by checkbox?

I am interested to have a data table as following in my shiny App. After I select the rows using the check boxes, I would like to continue working on the selected data. The problem now is I don't know how to get the index of the selected rows from this example. Can you please help? Thank you very much!

How do I make persistent checkboxes with DT::datatable in Shiny?

I think it has to do with the callback function. But I couldn't figure it out.




How can I resolve this Error inflating class CheckBox

Due to the fact that import kotlinx.android.synthetic.main is stuck when uploading the sdk to the project, I have been trying to do the migration but I can't get it to work. I have seen the viewbinding examples but I also see that it is in fragments and activities. I don't know if it doesn't work because I am using a :Dialog. What I have done is the following

class FragmentPruebaBinding(var activity: Activity, internal var adapter: AdapterPrueba) : Dialog(activity, R.style.AlertDialogStyle){
   var dialog: Dialog? = null

 override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       setContentView(R.layout.fragment_prueba)

        val activity: MainActivity = activity as MainActivity

        val Nombre: TextView = findViewById(R.id.Nombre)
        val check: CheckBox =findViewById(R.id.check)
        val btn_aceptar: Button = findViewById(R.id.btn_aceptar)
        val btn_cancelar: Button = findViewById(R.id.btn_cancelar)
        val nom: String = MainActivity.dataIdentities.activeIdent.name!! + " " + MainActivity.dataIdentities.activeIdent.snam!! + " " + MainActivity.dataIdentities.activeIdent.snam2
        Nombre.text =  nom
        check.setOnClickListener {
            adapter.setEnableAseg(!check.isChecked)
            adapter.notifyDataSetChanged()
        }
. . . 
}

the xml would look like this:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FragmentPruebaBinding">

    <LinearLayout
        android:id="@+id/LinearA"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:orientation="vertical"
        tools:ignore="MissingConstraints">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="170dp"
            android:fontFamily="@font/roboto"
            app:cardBackgroundColor="@color/color_background_cardview_seleccion_prueba"
            app:cardCornerRadius="18dp"
            app:cardElevation="5dp"
            app:cardPreventCornerOverlap="true"
            app:cardUseCompatPadding="true">

            <TextView
                android:id="@+id/Nombre"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="28dp"
                android:layout_marginTop="20dp"
                android:background="@color/color_background_cardview_seleccion_prueba"
                android:fontFamily="@font/roboto"
                android:textColor="@color/color_nombre"
                android:textSize="22sp"
                app:layout_constraintTop_toBottomOf="@id/header" />

            <TextView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="28dp"
                android:layout_marginTop="60dp"
                android:background="@color/color_background_cardview_seleccion_prueba"
                android:text="@string/header"
                android:textColor="@color/color_nombre"
                android:textSize="15sp" />


            <CheckBox
                android:id="@+id/check"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:layout_marginTop="90dp"
                android:fontFamily="@font/roboto"
                android:paddingStart="5dp"
                android:paddingEnd="0dp"
                android:text="@string/check_text"
                android:textColor="@color/color_letra_seleccion_prueba"
                android:textSize="16sp"
                app:buttonTint="@color/color_checkox_checked"
                app:layout_constraintTop_toBottomOf="@id/Nombre" />
        </androidx.cardview.widget.CardView>

    </LinearLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/white"
        app:layout_constraintBottom_toTopOf="@+id/btns_pruebas"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/LinearA" />

    <LinearLayout
        android:id="@+id/btns_pruebas"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <Button
            android:id="@+id/btn_cancelar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:backgroundTint="@color/cancel_button"
            android:fontFamily="@font/roboto"
            android:insetTop="0dp"
            android:insetBottom="0dp"
            android:text="@string/cancel"
            android:textSize="14sp"
            app:cornerRadius="0dp"
            app:strokeColor="@color/color_datos_02"
            app:strokeWidth="0.2dp" />

        <Button
            android:id="@+id/btn_aceptar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:backgroundTint="@color/accept_button"
            android:fontFamily="@font/roboto"
            android:insetTop="0dp"
            android:insetBottom="0dp"
            android:text="@string/aceptar"
            android:textSize="14sp"
            app:cornerRadius="0dp"
            app:strokeColor="@color/color_datos_02"
            app:strokeWidth="0.1dp" />

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

but I get the following error:

 android.view.InflateException: Binary XML file line #64 in ***:layout/fragment_prueba: Binary XML file line #64 in ***:layout/fragment_prueba: Error inflating class CheckBox
                                                                                                    Caused by: android.view.InflateException: Binary XML file line #64 in ***:layout/fragment_prueba: Error inflating class CheckBox
                                                                                                    Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}, theme={InheritanceMap=[id=0x7f150003***:style/AlertDialogStyle, id=0x7f150127***:style/FioriAlertDialogStyle, id=0x7f1503d1***:style/ThemeOverlay.MaterialComponents.MaterialAlertDialog, id=0x7f150086***:style/Base.ThemeOverlay.MaterialComponents.MaterialAlertDialog, id=0x7f15009a***:style/Base.V14.ThemeOverlay.MaterialComponents.MaterialAlertDialog, id=0x7f150375***:style/ThemeOverlay.AppCompat.Dialog.Alert, id=0x7f15007c***:style/Base.ThemeOverlay.AppCompat.Dialog.Alert, id=0x7f15007b***:style/Base.ThemeOverlay.AppCompat.Dialog, id=0x7f1500a4***:style/Base.V21.ThemeOverlay.AppCompat.Dialog, id=0x7f1500b8***:style/Base.V7.ThemeOverlay.AppCompat.Dialog, id=0x7f150077***:style/Base.ThemeOverlay.AppCompat, id=0x7f1501c1***:style/Platform.ThemeOverlay.AppCompat], Themes=[***:style/AlertDialogStyle, forced, ***:style/AppTheme.NoActionBar, forced, ***:style/Theme.AppCompat.Empty, forced, android:style/Theme.DeviceDefault.Light.DarkActionBar, forced]}
                                                                                                        at android.content.res.TypedArray.getColorStateList(TypedArray.java:600)
                                                                                                        at android.widget.TextView.readTextAppearance(TextView.java:4129)
                                                                                                        at android.widget.TextView.<init>(TextView.java:1128)
                                                                                                        at android.widget.Button.<init>(Button.java:166)
                                                                                                        at android.widget.CompoundButton.<init>(CompoundButton.java:104)
                                                                                                        at android.widget.CheckBox.<init>(CheckBox.java:71)
                                                                                                        at android.widget.CheckBox.<init>(CheckBox.java:67)
                                                                                                        at androidx.appcompat.widget.AppCompatCheckBox.<init>(AppCompatCheckBox.java:79)
                                                                                                        at com.google.android.material.checkbox.MaterialCheckBox.<init>(MaterialCheckBox.java:231)
                                                                                                        at com.google.android.material.checkbox.MaterialCheckBox.<init>(MaterialCheckBox.java:227)
                                                                                                        at com.google.android.material.theme.MaterialComponentsViewInflater.createCheckBox(MaterialComponentsViewInflater.java:49)
                                                                                                        at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:145)
                                                                                                        at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1569)
                                                                                                        at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1620)
                                                                                                        at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1065)
                                                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1001)
                                                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
                                                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
                                                                                                        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
                                                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
                                                                                                        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
                                                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
                                                                                                        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
                                                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
                                                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
                                                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:485)
                                                                                                        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:469)
                                                                                                        at android.app.Dialog.setContentView(Dialog.java:597)
                                                                                                        at ***.FragmentPruebaBinding.onCreate(FragmentPruebaBinding.kt:39)

the line 39 is:

setContentView(R.layout.fragment_aseguradora)

I tried this tutorial but to no avail either. I don't know what I'm missing https://developer.android.com/topic/libraries/view-binding/migration

Thanks for any help.




mardi 29 août 2023

Livewire 3 - Checkbox do not checked

I am doing a website and I'm on the new version of livewire 3, I am trying to do a checkbox All, but the problem is the value is on my tab but the checkbox dont want to checked: Checkbox do not checked

If someone can help me !

The view: first checkbox:

Code of the main checkbox

Both other: Other's checkbox code

Component:

Property

Function

We can see the id's on the array, but the checkbox dont check, and i already try to convert int in string but nothing happen: When i checked the main checkbox And if i checked the 2 down checkbox: When i checked the main and both other's

I guess the problem come from when i checked one of the 2 checkbox the function is called but should not.

If i look in the network, I don't see any update about my selected property: Network screen




lundi 28 août 2023

Extjs 4.2 grid Checkbox column not rendering checked when data from store is true

I have a data grid using Extjs 4.2 that has a checkbox coulmn with a data index = inactive. How can I get the checkbox to render as checked

Here is my data grid: { xtype: 'panel', title: 'Pricing', items: [ { xtype: 'gridpanel', height: 900, id: 'costGrid', title: 'Pricing', columnLines: true, store: 'CostStore', columns: [ { xtype: 'gridcolumn', hidden: true, dataIndex: 'id', text: 'Id' }, { xtype: 'gridcolumn', align: 'center', dataIndex: 'product', text: 'Product' }, { xtype: 'gridcolumn', renderer: function(value, metaData, record, rowIndex, colIndex, store, view) { return '<img src="' + '../' + value + '"width="100" height="100">' + "\n\r" + ' ' + record.data.description + ''; }, width: 371, align: 'center', dataIndex: 'imgSrc', text: 'ImgSrc' }, { xtype: 'gridcolumn', hidden: true, width: 272, dataIndex: 'description', text: 'Description' }, { xtype: 'gridcolumn', width: 154, align: 'center', dataIndex: 'resource', text: 'Resource' }, { xtype: 'gridcolumn', width: 88, align: 'center', dataIndex: 'cost', text: 'Cost', editor: { xtype: 'numberfield', selectOnFocus: true, allowExponential: false } }, { xtype: 'numbercolumn', width: 79, align: 'center', dataIndex: 'mfgCost', text: 'Mfg Cost', editor: { xtype: 'numberfield' } }, { xtype: 'numbercolumn', align: 'center', dataIndex: 'multiplier', text: 'Multiplier', editor: { xtype: 'numberfield' } }, { xtype: 'numbercolumn', align: 'center', dataIndex: 'flatRate', text: 'Flat Rate', editor: { xtype: 'numberfield' } }, { xtype: 'checkcolumn', dataIndex: 'inactive', text: 'Inactive', editor: { xtype: 'checkboxfield' } } ], plugins: [ Ext.create('Ext.grid.plugin.RowEditing', { pluginId: 'costPlugin', clicksToEdit: 1, listeners: { validateedit: { fn: me.onRowEditingValidateedit, scope: me } } }) ], dockedItems: [ { xtype: 'toolbar', dock: 'top', height: 79, width: 776, items: [ { xtype: 'combobox', id: 'productCombo', itemId: 'productCombo', padding: '10 10 10 10', fieldLabel: 'Product', labelWidth: 40, emptyText: '', editable: false, displayField: 'product', store: 'ProductStore', valueField: 'product', listeners: { change: { fn: me.onComboboxChange, scope: me } } }, { xtype: 'combobox', id: 'resourceCombo', itemId: 'resourceCombo', fieldLabel: 'Resource', labelWidth: 50, emptyText: '', editable: false, displayField: 'resource', store: 'ResourceStore', valueField: 'resource', listeners: { change: { fn: me.onResourceComboChange, scope: me } } }, { xtype: 'checkboxfield', padding: 20, width: 200, labelAlign: 'right', boxLabel: 'Check/Uncheck All', boxLabelAlign: 'before', listeners: { change: { fn: me.onCheckboxfieldChange, scope: me } } } ] } ], selModel: Ext.create('Ext.selection.CheckboxModel', { mode: 'SINGLE', showHeaderCheckbox: false }) } ] }

Here is the response from the store get request

[{"id":"1","product":"Casket","imgSrc":"./files/parag/thumb/Princeton_cjb_tn.jpg","description":"Princeton Solid Mahogany","resource":"Paragon","cost":"19500.00","mfgCost":"13000.00","multiplier":"1.50","flatRate":null,"inactive":"1"},

I tried an event change on the checkbox to no avail. Please if someone can send me down the right path I would greatly appreciate it.




samedi 26 août 2023

Add attribute to checkbox so it can fire button click event

I have a button on my page which is a trigger for an update panel. The page does not refresh and all the variables on the page (sender) go into the btncalcsave_click event just fine. Instead of having to check a checkbox and click the button that is wired to the click event, I want to be able to just click the checkbox and btncalcsave_click will fire as when I click the button. How is this achieved?

I tried to add a trigger to the update template (cbbiweekly) which is the id of the checkbox but this doesn't work. Does the checkbox need to have an Onclick attribute added to it in order for this to work? I am unclear how to get this working.

<asp:CheckBox ID="cbbiweekly" runat="server" Text="Bi-Weekly Pmt Schedule" Font-Size="x-Small"  OnClientClick="btncalcsave_Click" />

<asp:UpdatePanel ID="udppmtschedule" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btncalcsave" />
            <asp:AsyncPostBackTrigger ControlID="cbbiweekly" />
        </Triggers>
        <ContentTemplate>
            <table width="450px">



Table with checkboxes losing its checked state on a page scroll (no lazy-loading or virtual scrolling is implemented) in react js

I have a table in react js which has a column of checkboxes. On clicking the table header's checkbox, all of the children / table-row checkboxes gets checked. But when the table or page is scrolled. The checkboxes present in table row gets unchecked automatically, that is, the checked value is turning from true to false. Below is the code:

<table className="table">
 <tbody>
  <tr>
   <td className="cell">
     <span className="select-all">
      <input onChange={selectAllClicked} type="checkbox" value="24">
     <span/>
   <td/>
  <tr/>
  <tr>
   <td className="cell">
     <span className="child-input">
      <input type="checkbox" value="24">
     <span/>
   <td/>
  <tr/>
  <tr>
   <td className="cell">
     <span className="child-input">
      <input type="checkbox" value="24">
     <span/>
   <td/>
  <tr/>
<tbody/>

Below is the event handler used:

function selectAllClicked() {
  $("span.child-input input").prop("checked", $(".select-all input").is(":checked"));
}

It would be really helpful if someone helps me in resolving this issue.