Update numeric validation patch and round out example1

This commit is contained in:
Matthew R. Wilson committed 2023-11-11 15:02:02 -08:00
1 parent 54e3008e26
commit efb8f9edf9
2 files changed
+22 -17

No files matched your search

+12 -10
View File
@@ -33,8 +33,8 @@ var screen1 = go3270.Screen{
{Row: 6, Col: 0, Content: "Password . . . ."}, {Row: 6, Col: 0, Content: "Password . . . ."},
{Row: 6, Col: 19, Name: "password", Write: true, Hidden: true}, {Row: 6, Col: 19, Name: "password", Write: true, Hidden: true},
{Row: 6, Col: 40}, // field "stop" character {Row: 6, Col: 40}, // field "stop" character
{Row: 7, Col: 0, Content: "EmployeeId . . . ."}, {Row: 7, Col: 0, Content: "Employee ID . . ."},
{Row: 7, Col: 19, Name: "employeeId", Write: true, Highlighting: go3270.Underscore, NumericOnly: true}, {Row: 7, Col: 19, Name: "employeeID", Write: true, Highlighting: go3270.Underscore, NumericOnly: true},
{Row: 7, Col: 40}, // field "stop" character {Row: 7, Col: 40}, // field "stop" character
{Row: 8, Col: 0, Content: "Press"}, {Row: 8, Col: 0, Content: "Press"},
{Row: 8, Col: 6, Intense: true, Content: "enter"}, {Row: 8, Col: 6, Intense: true, Content: "enter"},
@@ -50,14 +50,16 @@ var screen2 = go3270.Screen{
{Row: 4, Col: 19, Name: "fname"}, // We're giving this field a name to replace its value at runtime {Row: 4, Col: 19, Name: "fname"}, // We're giving this field a name to replace its value at runtime
{Row: 5, Col: 0, Content: "And your last name is"}, {Row: 5, Col: 0, Content: "And your last name is"},
{Row: 5, Col: 22, Name: "lname"}, // We're giving this field a name to replace its value at runtime {Row: 5, Col: 22, Name: "lname"}, // We're giving this field a name to replace its value at runtime
{Row: 6, Col: 0, Name: "passwordOutput"}, {Row: 6, Col: 0, Content: "And your employeed ID is"},
{Row: 8, Col: 0, Content: "Press"}, {Row: 6, Col: 22, Name: "employeeID"}, // We're giving this field a name to replace its value at runtime
{Row: 8, Col: 6, Intense: true, Content: "enter"}, {Row: 7, Col: 0, Name: "passwordOutput"},
{Row: 8, Col: 12, Content: "to enter your name again, or"}, {Row: 9, Col: 0, Content: "Press"},
{Row: 8, Col: 41, Intense: true, Content: "PF3"}, {Row: 9, Col: 6, Intense: true, Content: "enter"},
{Row: 8, Col: 45, Content: "to quit and disconnect."}, {Row: 9, Col: 12, Content: "to enter your name again, or"},
{Row: 11, Col: 0, Color: go3270.Turquoise, Highlighting: go3270.ReverseVideo, Content: "Here is a field with extended attributes."}, {Row: 9, Col: 41, Intense: true, Content: "PF3"},
{Row: 11, Col: 42}, // remember to "stop" fields with a regular field, to clear the reverse video for example {Row: 9, Col: 45, Content: "to quit and disconnect."},
{Row: 12, Col: 0, Color: go3270.Turquoise, Highlighting: go3270.ReverseVideo, Content: "Here is a field with extended attributes."},
{Row: 12, Col: 42}, // remember to "stop" fields with a regular field, to clear the reverse video for example
{Row: 22, Col: 0, Content: "PF3 Exit"}, {Row: 22, Col: 0, Content: "PF3 Exit"},
} }
+10 -7
View File
@@ -40,7 +40,9 @@ type Field struct {
// password input field). // password input field).
Hidden bool Hidden bool
// NumericOnly if set only allows numeric input to be written to the field // NumericOnly indicates that only numbers may be entered into the field.
// Very fiew 3270 clients support this, so you must always still validate
// the input on the server side.
NumericOnly bool NumericOnly bool
// Color is the field color. The default value is the default color. // Color is the field color. The default value is the default color.
@@ -196,7 +198,8 @@ func buildField(f Field) []byte {
if f.Color == DefaultColor && f.Highlighting == DefaultHighlight { if f.Color == DefaultColor && f.Highlighting == DefaultHighlight {
// this is a traditional field, issue a normal sf command // this is a traditional field, issue a normal sf command
buf.WriteByte(0x1d) // sf - "start field" buf.WriteByte(0x1d) // sf - "start field"
buf.WriteByte(sfAttribute(f.Write, f.Intense, f.Hidden, f.Autoskip, f.NumericOnly)) buf.WriteByte(sfAttribute(f.Write, f.Intense, f.Hidden, f.Autoskip,
f.NumericOnly))
return buf.Bytes() return buf.Bytes()
} }
@@ -213,7 +216,8 @@ func buildField(f Field) []byte {
// Write the basic field attribute // Write the basic field attribute
buf.WriteByte(0xc0) buf.WriteByte(0xc0)
buf.WriteByte(sfAttribute(f.Write, f.Intense, f.Hidden, f.Autoskip, f.NumericOnly)) buf.WriteByte(sfAttribute(f.Write, f.Intense, f.Hidden, f.Autoskip,
f.NumericOnly))
// Write the highlighting attribute // Write the highlighting attribute
if f.Highlighting != DefaultHighlight { if f.Highlighting != DefaultHighlight {
@@ -242,7 +246,9 @@ func sfAttribute(write, intense, hidden, skip, numeric bool) byte {
// The MDT bit -- we always want writable field values returned, // The MDT bit -- we always want writable field values returned,
// even if unchanged // even if unchanged
attribute |= 1 // set "bit 7" attribute |= 1 // set "bit 7"
if numeric {
attribute |= 1 << 4 // set "bit 3"
}
} }
if intense { if intense {
attribute |= 1 << 3 // set "bit 4" attribute |= 1 << 3 // set "bit 4"
@@ -251,9 +257,6 @@ func sfAttribute(write, intense, hidden, skip, numeric bool) byte {
attribute |= 1 << 3 // set "bit 4" attribute |= 1 << 3 // set "bit 4"
attribute |= 1 << 2 // set "bit 5" attribute |= 1 << 2 // set "bit 5"
} }
if numeric {
attribute |= 1 << 4 // set "bit 3"
}
// Fill in top 2 bits with appropriate values // Fill in top 2 bits with appropriate values
attribute = codes[attribute] attribute = codes[attribute]
return attribute return attribute