mardi 2 février 2021

Expandable drop down with Multi select checkbox in Swift

check / uncheck the check box by tapping the cell in table view and how to know which cell has checked or unchecked inside Expandable drop down in Swift.

VBExpandVC

class VBExpandVC: UIViewController,UITableViewDelegate,UITableViewDataSource {

    @IBOutlet var myTableView: UITableView!
    
    struct Notification:Codable {
        let notification:[Headings]
    }
    
    struct Headings:Codable {
        var name:String
        var status:Int
    }
       
    var names = [Headings]()

    var expandTableview:VBHeader = VBHeader()
    var cell : VCExpandCell!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        getNotifications()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
    {
        expandTableview = Bundle.main.loadNibNamed("VBHeader", owner: self, options: nil)?[0] as! VBHeader
        let layer = expandTableview.viewHeader.layer
        layer.shadowColor = UIColor.black.cgColor
        layer.shadowOffset = CGSize(width: 0, height: 1)
        layer.shadowOpacity = 0.4
        expandTableview.lblDate.text = self.names[section].name
        expandTableview.btnExpand.tag = section
        expandTableview.btnExpand.addTarget(self, action: #selector(VBExpandVC.headerCellButtonTapped(_sender:)), for: UIControl.Event.touchUpInside)

        let str:String = "\(self.names[section].status)"//arrStatus[section] as! String
        if str == "0"
        {
            UIView.animate(withDuration: 2) { () -> Void in
                self.expandTableview.imgArrow.image = UIImage(named :"switch")
            }
        }
        else
        {
            UIView.animate(withDuration: 2) { () -> Void in
                self.expandTableview.imgArrow.image = UIImage(named :"switch2")
            }
        }

        return expandTableview
    }

    @objc func headerCellButtonTapped(_sender: UIButton)
    {
        print("header tapped at:")
        print(_sender.tag)
        var str:String = "\(self.names[_sender.tag].status)"
        if str == "0"
        {
            self.names[_sender.tag].status = 1
        }
        else
        {
            self.names[_sender.tag].status = 0
        }
//        myTableView.reloadData()
        myTableView.reloadSections([_sender.tag], with: .none)
    }

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
    {
        //Return header height as per your header hieght of xib
        return 40
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        let str:Int = (names[section].status)
        if str == 0
        {
            return 0
        }
        return  1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
        cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? VCExpandCell
        return cell;
    }

    func numberOfSections(in tableView: UITableView) -> Int
    {
        return self.names.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
    {
        //Return row height as per your cell in tableview
        return 111
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("selected:\(indexPath.section)")
    }
    
    // getNotifications
    func getNotifications(){
        guard let url = URL(string: "https://www.json-generator.com/api/json/get/cgAhRPmZgy?indent=2") else {
            return
        }
        var request = URLRequest(url: url)
        request.httpMethod = "GET"
        
        URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in
            guard let data = data, error == nil, response != nil else {
                return
            }
            
            do {
                let headings = try JSONDecoder().decode(Notification.self, from: data)
                self.names = headings.notification
                DispatchQueue.main.async {
                    self.myTableView.reloadData()
                }
            } catch {
                print(error)
            }
        }).resume()
    }
    // End
}

VCExpandCell

class VCExpandCell: UITableViewCell {
    
    @IBOutlet weak var btnMobile: UIButton!
    @IBOutlet weak var btnEmail: UIButton!
    @IBOutlet weak var btnSms: UIButton!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }
    
    @IBAction func btnMobileApp(_ sender: UIButton) {
        print("mobile app checked")
        print(sender.tag)
        if sender.isSelected {
            sender.isSelected = false
        } else {
            sender.isSelected = true
        }
    }
    
    @IBAction func btnSMS(_ sender: UIButton) {
        print("sms checked")
        print(sender.tag)

        if sender.isSelected {
          sender.isSelected = false
      } else {
          sender.isSelected = true
      }

    }

    @IBAction func btnEmail(_ sender: UIButton) {
        print("email checked")
        print(sender.tag)
        if sender.isSelected {
            sender.isSelected = false
        } else {
            sender.isSelected = true
        }
    }
    
}

enter image description here

In the above code, I have two major problems.

  1. selected check box positions are changing when expanded the section and expanded another section

  2. Unable to find selected check boxes by tapping the cell in table view inside Expand drop down.




Add checkbox to a dropdown in plotly dash

This might be a FAQ, but I did not find any solution for plotly dash. I don't have any html or css knowledge. I need to add a checkbox next to every option in the dropdown.

I also tried to add my custom class to the css stylesheet -

.checked[type="checkbox"]:before {
  width: 10px;
  height: 10px;
}

But, adding this option in className also does not help. I am not looking for multi=True , as the user will have to re-open the dropdown again to select next option. The file /assets/bWLwgP.css is the usual bWLwgP.css downloadable from "https://ift.tt/2yOOoWS"

import dash
import dash_html_components as html
import dash_core_components as dcc

external_stylesheets = ["/assets/bWLwgP.css)"]

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
    dcc.Dropdown(
        id='demo-dropdown',
        options=[
            {'label': 'New York City', 'value': 'NYC'},
            {'label': 'Montreal', 'value': 'MTL'},
            {'label': 'San Francisco', 'value': 'SF'}
        ],
        value='NYC', multi=False, className="checked"
    ),
    html.Div(id='dd-output-container'), 
])


@app.callback(
    dash.dependencies.Output('dd-output-container', 'children'),
    [dash.dependencies.Input('demo-dropdown', 'value')])
def update_output(value):
    return 'You have selected "{}"'.format(value)


if __name__ == '__main__':
    app.run_server(debug=True)



lundi 1 février 2021

find the right answer [closed]

I have created a page with quiz questions.I write a question and I have checkboxes.Is there a way someone can "detect" with somehow the questions which is right or wrong?The student's can use something to detect the right answer?




Change src related to "Radio Button Checks"

In my project I want change src part (ar-button's src) related to my radio buttons check.

For ex: When you check "Option 1" I want to change src part on ar-button. Than when you check Option3x(with checked option1 and option1x) I want to change src again.

I mean for all 64 combination of checks I want to change src.

Any help or suggestion would be great!

Thanks..

                    <label>
                        <input type="radio" id="diffuse" name="kumas" value="textues/kumas/2/pgwfpjp_2K_Albedo.jpg"checked>
                        Option1
                    </label>
            
                    <label>
                        <input type="radio"id="adiffuse" name="kumas" value="textues/kumas/1/oi2veqp_2K_Albedo.jpg">
                       Option 2
                    </label>

                    <label>
                        <input type="radio" id="bdiffuse"name="kumas" value="textues/kumas/3/sjfvce3c_2K_Albedo.jpg">
                        Option 3
                    </label>

                    <label>
                        <input type="radio" id="cdiffuse"name="kumas" value="textues/kumas/4/sjfvcjzc_2K_Albedo.jpg">
                     Option 4
                    </label>
                    
                    
<br><br>




                    <label>
                        <input type="radio" id="diffuse1" name="kol" value="textues\kol\1\teqbcizc_2K_Albedo.jpg" checked>
                        Option 1x
                    </label>

                    <label>
                        <input type="radio" id="adiffuse1" name="kol" value="textues\kol\2\tfjbderc_2K_Albedo.jpg">
                       Option 2x
                    </label>

                    <label>
                        <input type="radio" id="bdiffuse1"name="kol" value="textues\kol\3\tcnodi3c_2K_Albedo.jpg">
                        Option 3x
                    </label>

                    <label>
                        <input type="radio" id="cdiffuse1"name="kol" value="textues\kol\4\tcicdebc_2K_Albedo.jpg">
                      Option 4x
                    </label>
  

                </div>
            
            </div>

        </div>



<br><br>

                    <label>
                        <input type="radio" id="diffuse2" name="dugme" value="textues\metal\1\scksebop_2K_Albedo.jpg"  checked>
                       Option 1z
                    </label>

                    <label>
                        <input type="radio" id="adiffuse2" name="dugme" value="textues\metal\2\se4objgc_2K_Albedo.jpg">
                       Option 2z
                    </label>

                    <label>
                        <input type="radio" id="bdiffuse2"name="dugme" value="textues\metal\3\se4pcbbc_2K_Albedo.jpg">
                        Option 3z
                    </label>

                    <label>
                        <input type="radio" id="cdiffuse2"name="dugme" value="textues\metal\4\shkxcgfc_2K_Albedo.jpg">
                     Option 4z
                    </label>


<br><br>
                    
                    
    <ar-button

    id="change" src="https://basebros.com/models/ar_base_tekli_koltuk_3d.glb"
    
    id="change2 ios-src="https://basebros.com/models/ar_base_tekli_koltuk_3d.usdz"
    
    title="3D-AR by BASE">
    
    <img class="arbuttonicon" src="Assets/evindebutton.png" width="170px" alt="AR-icon">
    
    </ar-button>       
                    
                    

     



how can i transilate english to arabic language using checkbox toggle button

i am working in python-Django.I need to convert english to arabic language by using checkbox

<input type="checkbox" id="che" style="margin-top: 30px;padding-top: 15px;">


#che {
-webkit-appearance: none;
position: relative;
width: 80px;
height: 40px;
background-image: url(../images/us.png);
background-size: cover;
border-radius: 50px;
outline: none;
transition: background-image .90s;
box-shadow: 0px 2px 5px 1px gray;

}

#che:before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 40px;
width: 40px;
background-color: navy;
border-radius: 50px;
transition: all .9s;
background-color: #004d66;

}

#che:checked {
background-image: url(../images/kwd.png);

transition: background-image .90s;

}

#che:checked:before {
transform: translate(100%);
transition: all .9s;
background-color: #ECF0F3;

}

this is the image of my checkbox-toggle button




Sort data collection_check_boxes

I have a collection_check_boxes with custom data. In my model I have a method like this:

def label
   [social_profile.name, I18n.t(source_type_code, scope: 'enum.source_type.name')].join(' - ')
end

And in my view I have this:

= f.collection_check_boxes(:source_ids, @sources, :id, :label)

But I need to sort the data returned by my method label alphabetically. How can I do that? Thank you!




Javascript button click in another url

There are url1 and url2. I am in url1. url2 has a checkbox and a button that I want to check and click. url1 has a button that I made and when I click it then...

  1. open window in url2.
  2. check the checkbox.
  3. click the button.

However, my button will only open a window with url2 and it will not check the checkbox nor click the button. Maybe the website isn't loaded yet?

I hope it doesn't open a window in url2 and just check the checkbox and click the button if it's possible. If that's impossible then teach me how to fix this so 1),2),3) will be executed in the right order, please.

My codes are...

function reply_del1() {
var button1 = document.createElement("button");
button1.innerHTML = "DeleteComments";

var body1 = document.getElementsByTagName("body")[0];
body1.appendChild(button1);

button1.addEventListener ("click", function() {

var url2 = "http://somesite12345.com/attendance/cmt.php";//1)
window.open(url2);

$('#check_all').trigger('click');//2)

document.getElementsByName("btn_delete")[0].click();//3)
});
}